From: Phrogz Date: 2007-11-18T14:25:06+09:00 Subject: Re: make a hash object to string object as look like a hash ? On Nov 17, 9:41 pm, Pokkai Dokkai wrote: > now i am facing new problem.... > > h={:a=>'aaa',:f=>BigDecimal.new("10")} > h.inspect -----> {:f=>#, > :a=>"aaa"} > > i want like this----->{:f=>10, :a=>"aaa"} irb(main):002:0> require 'bigdecimal' => true irb(main):003:0> h = { :a=>'aaa', :f=>BigDecimal.new("10") } => {:f=>#, :a=>"aaa"} irb(main):005:0> h[:f].to_i => 10 irb(main):006:0> class BigDecimal; alias_method :inspect, :to_i; end => BigDecimal irb(main):007:0> h => {:f=>10, :a=>"aaa"} #inspect methods of classes that aggregate other instances tend to call the #inspect of all those instances; you can customize the inspect method of each class to customize its output. (Here I've just said "make it so that when I call .inspect on a BigDecimal instance, instead call the to_i method.")