Created
February 18, 2012 06:48
-
-
Save hitode909/1857903 to your computer and use it in GitHub Desktop.
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
module PrintSelf | |
def inspect | |
args = self.method(:initialize).parameters.map{ |param| | |
self.instance_variable_get("@#{param[1]}".to_sym).inspect | |
} | |
"#{self.class}.new(#{args.join(", ")})" | |
end | |
end |
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
$:.push('.') | |
require 'print_self' | |
class Human | |
include PrintSelf | |
def initialize(name, age) | |
@name = name | |
@age = age | |
end | |
end | |
p Human.new('inoue', 13) # => Human.new("inoue", 13) | |
p eval(Human.new('inoue', 13).inspect) # => Human.new("inoue", 13) | |
p eval(eval(eval(eval(Human.new('inoue', 13).inspect).inspect).inspect).inspect) # => Human.new("inoue", 13) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment