Skip to content

Instantly share code, notes, and snippets.

@stevenbristol
Created August 1, 2012 12:38
Show Gist options
  • Save stevenbristol/3226460 to your computer and use it in GitHub Desktop.
Save stevenbristol/3226460 to your computer and use it in GitHub Desktop.
instance_eval and class_eval 1
String.instance_eval do
def from_instance_eval
self
end
end
String.class_eval do
def from_class_eval
self
end
end
p String.from_instance_eval #String
p "string".from_class_eval #"string"
begin
String.from_class_eval
rescue Exception => e
p e # => #<NoMethodError: undefined method `from_class_eval' for String:Class>
end
begin
"string".from_instance_eval
rescue Exception => e
p e # => #<NoMethodError: undefined method `from_instance_eval' for "string":String>
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment