ToReference
A simple solution to convert any ruby method to a reference. Just like in Javascript, you can pass around and call these references at a later time."
Installation
Add the to_reference gem to your Gemfile:
gem "to_reference"
Update your bundle and run the install generator:
$ bundle install
Usage
Converts both instance and class methods to a reference.
require 'to_reference'
Class Foo
include ToReference
def hi
"hi"
end
def self.bar(params)
"gr" + params
end
reference :hi, :bar
Now you can do
ref1 = Foo.new.hi
ref2 = Foo.bar
ref1.call => # "hi"
ref2.call("eat!") => # "great!"
Will also work with methods that are inherited, included, extended etc. Want more examples ? Check out examples
Bugs and Feedback
If you discover any bugs or want to drop a line, feel free to create an issue on GitHub.