From: Brian Candler Date: 2009-02-11T23:43:34+09:00 Subject: Re: simple class question Tom Cloyd wrote: > With execution stopped, I enter at the command line: > > (rdb:1) p test.t2 = 2 > 2 > > I should have gotten 4. I only ever get back the same number I put in. > Can someone tell me what the problem is, and what I have to do to get > test.t2 to do this simple thing I'm asking of it? Just to make it clear, although you probably realise by now: you're not calling test.t2, you're calling test.t2= The name of the method really does contain the = sign, and is actually the symbol :t2= Operators are other examples of non-alphanumeric method names: class Test def +(other) .. do something end def [](key) .. end def [](key, value) .. end end So you can make your own class look like a Ruby one: t = Test.new puts t + 1 # calls your :+ method puts t[123] # calls your :[] method t[123] = 456 # calls your :[]= method I especially like :[] - smiley programming :-) Regards, Brian. -- Posted via http://www.ruby-forum.com/.