Skip to content

Instantly share code, notes, and snippets.

@leandrosilva
Created November 9, 2009 18:05
Show Gist options
  • 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