Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
$:.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
You can’t perform that action at this time.