From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2003-03-15T10:23:23+09:00 Subject: Overloaded operator interprets block as hash I'm trying to define an operator that takes a block, like: a << {puts "Action!"} but the part in '{}' gets interpreted as a hash. Here's the sample code: class Foo def initialize(&proc) @closure = proc end def assign(newVal = Proc.new) @closure = newVal end def <<(newVal = Proc.new) @closure = newVal end def callit @closure.call end end f= Foo.new { puts "Action!" } f.callit #=> "Action!" f.assign { puts "New Action!" } f.callit #=> "New Action!" f<< { puts "Latest Action!" } SyntaxError: compile error (irb):26: parse error f << { puts "Latest Action!" } ^ from (irb):26 .... it seems as though the block being passed to '<<' is getting interpreted as a hash while it isn't for the 'assign' method. Is there anyway around this? Phil