Consider the following code:
class Stuff
def << (arg1,arg2)
puts arg1
puts arg2
end
end
s = Stuff.new
When doing the following:
s << "1", "2"
Ruby errors with:
stuff:8: parse error, unexpected ',', expecting ')'
When doing:
s << "1"
Ruby expects 2 arguments instead of one (which is right).
But when doing:
s.<< "1", "2"
suddenly everything works. To me, this seems a bit weird, since I
expected that s << is syntactic sugar for s.<<, but the implementation
seems different. Also using <<(*args) in the method definition doesn't
do what I expect it to do. Of course I can work around not using s <<
with multiple arguments, but I'm just curious what the design principles
are behind this behaviour.
--
Posted via http://www.ruby-forum.com/.