Skip to content

Instantly share code, notes, and snippets.

@leandrosilva
Created November 9, 2009 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leandrosilva/230140 to your computer and use it in GitHub Desktop.
Save leandrosilva/230140 to your computer and use it in GitHub Desktop.
New method implementation with instance_eval
#
# 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