Philip Mak <pmak / aaanime.net> 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