Created
November 9, 2009 18:05
-
-
Save leandrosilva/230140 to your computer and use it in GitHub Desktop.
New method implementation with instance_eval
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
# | |
# Some class for example | |
# | |
class SomeClass | |
def a_method | |
puts '>> a defined method: a_method' | |
end | |
end | |
# | |
# new method implementation with instance_eval | |
# | |
puts 'new method implementation with instance_eval...' | |
obj = SomeClass.new | |
new_method_name = 'a_new_method' | |
obj.instance_eval %Q{ | |
def #{new_method_name} | |
a_method | |
puts ">> a new added method: #{new_method_name}" | |
end | |
} | |
obj.send(new_method_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment