From: Erik Veenstra Date: 2007-02-09T19:39:58+09:00 Subject: Re: Your favorite bit of ruby code? In general, AFAIK, an initialize can be skipped if all it does is a super with the same arguments. What am I missing? I want to learn... ;] gegroet, Erik V. - http://www.erikveen.dds.nl/ ---------------------------------------------------------------- require "test/unit" class Functor < Proc private *instance_methods.select { |m| m !~ /(^__|^\W|^binding$)/ } #def initialize(&function) #super(&function) #end def method_missing(op, *args, &blk) call(op, *args, &blk) end end class TestFunctor < Test::Unit::TestCase def test_it f = Functor.new { |op, x| x.send(op, x) } assert_equal(2, f+1) assert_equal(4, f+2) assert_equal(6, f+3) assert_equal(1, f*1) assert_equal(4, f*2) assert_equal(9, f*3) end end ---------------------------------------------------------------- $ ruby functor.rb Loaded suite functor Started . Finished in 0.0 seconds. 1 tests, 6 assertions, 0 failures, 0 errors ----------------------------------------------------------------