An open API service indexing awesome lists of open source software.

https://github.com/grodowski/ruby_method_call_counter

Count invocations of a method from an arbitrary Ruby script
https://github.com/grodowski/ruby_method_call_counter

Last synced: 3 months ago
JSON representation

Count invocations of a method from an arbitrary Ruby script

Awesome Lists containing this project

README

          

[![codebeat badge](https://codebeat.co/badges/794bb9da-167d-4a39-a505-b96754b20088)](https://codebeat.co/projects/ruby_method_call_counter-master)

MethodCallCounter
===

**Count invocations of an arbitraty method in Ruby** - `solution.rb` required on top of your host script expects the target method signature in an environment variable `COUNT_CALLS_TO`. Given `COUNT_CALLS_TO` has a correct method signature, the script will print the number of target method's invocations at the end of execution.

Valid method signatures:
```
Math.sin
ActiveRecord::Base.connection
String#size
Foo.bar
Post#status
etc...
```

Example
---
Require on app load:
```
# spec_helper.rb
...
require_relative '../../solution.rb'
...
```

Execute a Ruby script with `COUNT_CALLS_TO` set to count invocations of `Hash#dup`
```
$ COUNT_CALLS_TO='Hash#dup' rspec spec/controllers
# some output
Hash#dup has been invoked 2768 times
```

To Do
---
* Exception handling
* Handle optional parameters more gracefully
* Add more tests

Feel free to **contribute** to this project by submitting pull requests! We can create something useful together, maybe :)