Skip to content

Instantly share code, notes, and snippets.

@ngpestelos
Created September 22, 2013 10:59
Show Gist options
  • Save ngpestelos/6658895 to your computer and use it in GitHub Desktop.
Save ngpestelos/6658895 to your computer and use it in GitHub Desktop.
class eval
# see Metaprogramming Ruby, p. 93
def add_method_to(a_class)
a_class.class_eval do
def m; 'Hello!'; end
end
end
add_method_to String
puts "foo".m # Hello!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment