From: kris Date: 2006-04-29T18:52:24+09:00 Subject: Re: class returns value without method or attribute I like the idea of using inspect, will this also allow me to assign value like: money = Money.new money = 5 Also do I need to add a method for + and -, is there not a module like Comparable that I can mixin to get this functionality? Are there any other typical methods I should be adding? Excluding the money specific stuff I have to_s. Many thanks for all the replies they have been really helpful. Gordon Thiesfeld wrote: >>If I have a class how do I get it to return a value without specifying a >>method or attribute: >> > > You want to overload the inspect method: > > class Money > attr_accessor :value > > def initialize(value) > @value = value > end > > def inspect > @value > end > > end > > irb(main):001:0> require 'money' > => true > irb(main):002:0> money = Money.new(5) > => 5 > irb(main):003:0> money > => 5 -- Posted via http://www.ruby-forum.com/.