Created
June 20, 2011 08:20
-
-
Save Marchino/1035291 to your computer and use it in GitHub Desktop.
Recursive send method for Ruby Objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Lets you call object.rsend('method1.method2.method3') instead of object.send('method1').send('method2).send('method3) | |
class Object | |
def rsend(method, *params) | |
method.to_s.split('.').inject(self) { |obj, mth| obj.send(mth.to_sym, *params) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment