From: Brian Candler Date: 2009-11-16T19:27:02+09:00 Subject: Re: Newbie question: Defining a numeric type Seebs wrote: > I think I'm thinking something like the Comparable mixin; sort of a > "I have a to_i, make me a number" module. You could just delegate to the number: class Foo def initialize(n) @n = n end def to_int @n end def method_missing(*args) to_int.send(*args) end end f = Foo.new(12) puts f + 3 puts 2 + f Note that there is a subtle distinction between to_int and to_i, as there is between to_str and to_s. I think you want to_int here, since you are declaring that your object is, to all intents and purposes, an integer. You could also look at the #coerce method, but I don't think it's needed here. -- Posted via http://www.ruby-forum.com/.