From: Tony Arcieri Date: 2011-01-27T05:52:12+09:00 Subject: Re: Coercion in Ruby --001636c5a8a4ee6422049ac5ba17 Content-Type: text/plain; charset=ISO-8859-1 Just a small nitpick: if other.is_a? TimeInterval TimeInterval.new(value + other.value) elsif other.is_a? Numeric TimeInterval.new(value + other) else raise TypeError, "#{other.class} can't be coerced into TimeInterval" end would probably be better written as: case other when TimeInterval TimeInterval.new(value + other.value) when Numeric TimeInterval.new(value + other) else raise TypeError, "#{other.class} can't be coerced into TimeInterval" end On Wed, Jan 26, 2011 at 7:58 AM, zdennis wrote: > A fellow rubyist, Zach Church, wrote a great article on coercion in > Ruby. It's not something I've seen covered often so I thought I'd > share with the community at large: > > http://mutuallyhuman.com/blog/2011/01/25/class-coercion-in-ruby > > Zach Dennis > > -- Tony Arcieri Medioh! Kudelski --001636c5a8a4ee6422049ac5ba17--