From: Sam Roberts Date: 2003-03-16T02:24:34+09:00 Subject: Re: Overloaded operator interprets block as hash (bug?) Quoteing ptkwt@shell1.aracnet.com, on Sat, Mar 15, 2003 at 05:44:40PM +0900: > In article , > Phil Tomson wrote: > >In article <3E729E3F.7020007@day-reynolds.com>, > >Lennon Day-Reynolds wrote: > >True, but... > >1) I'm sort of creating a domain specific language from Ruby (an HDL) and > >I'm trying to hide that sort of thing from the user. > >2) I'm wondering if this is some sort of bug? > > I was just talking to some folks on IRQ and Apparently it's not a bug, > you've got to do: > f.<< {puts "An Action"} > > The '.' is needed in this case. Yeah, but in that case you're just calling << directly as if it was a function, so why not just MAKE a function: f.add {puts "an Action"} Having a method with the same name as an operator << is useful so that ruby hooks statements like a << b and converts the statement to a.<<(b) I think having a method called << that can't actually be used as a << b is pretty confusing! :-) I guess its not considered a bug because a block isn't an arg, and the ruby syntax doesn't allow blocks on binary operators, it appears, I just tried! [ensemble] ~/p/ruby/vcard $ irb irb(main):001:0> class T; def <<(arg); yield "hi #{arg}"; end; end nil irb(main):002:0> t = T.new # irb(main):005:0> t << 5 { |y| p y } SyntaxError: compile error (irb):5: parse error t << 5 { |y| p y } ^ from (irb):5 Cheers, Sam