From: Martin DeMello Date: 2003-01-22T08:58:40+09:00 Subject: Re: Overloading operators Philip Mak wrote: > Is there a shortcut for writing all this? > > def +(otherField) > @value + otherField.value > end Remembering that code within a class definitionbut outside a method definition gets executed once only, when Ruby reads the class definition in: class Test attr_accessor :value def initialize(value) @value = value end %w(+ - * /).each {|op| class_eval %Q{ def #{op}(otherField) @value #{op} otherField.value end } } end a = Test.new(5) b = Test.new(6) puts a + b