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
- Host: GitHub
- URL: https://github.com/grodowski/ruby_method_call_counter
- Owner: grodowski
- License: mit
- Created: 2014-12-13T18:48:54.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2017-02-26T13:19:52.000Z (almost 9 years ago)
- Last Synced: 2025-02-01T02:27:29.915Z (12 months ago)
- Language: Ruby
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](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 :)