/trunk/Examples/ruby/functor/runme.rb

# · Ruby · 17 lines · 9 code · 5 blank · 3 comment · 0 complexity · a2d12520a37a807f3d7c6d2c403b1907 MD5 · raw file

  1. # Operator overloading example
  2. require 'example'
  3. a = Example::IntSum.new(0)
  4. b = Example::DoubleSum.new(100.0)
  5. # Use the objects. They should be callable just like a normal
  6. # Ruby function.
  7. (0..100).each do |i|
  8. a.call(i) # note: function call
  9. b.call(Math.sqrt(i)) # note: function call
  10. end
  11. puts a.result
  12. puts b.result