Created
August 1, 2012 12:38
-
-
Save stevenbristol/3226460 to your computer and use it in GitHub Desktop.
instance_eval and class_eval 1
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
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