class Gift def initialize @name = "book" @price = 15.95 endendgift = Gift.newhash = {}gift.instance_variables.each {|var| hash[var.to_s.delete("@")] = gift.instance_variable_get(var) }p hash # => {"name"=>"book", "price"=>15.95}
Комментариев нет:
Отправить комментарий