Created
July 12, 2012 06:51
-
-
Save inre/3096345 to your computer and use it in GitHub Desktop.
Nice define method
This file contains 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
class Object | |
def def(method, &b) | |
self.class.send(:define_method, method, &b) | |
end | |
end |
This file contains 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
# define method | |
object = Class.new | |
object.def :foo do |arg| | |
puts arg | |
end | |
# call method | |
object.foo("Hello world"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment