J
John Woods
I'm trying to redefine the >> operator for a particular class such that
it takes a block as its argument. It works if I invoke the redifined >>
operator using "." syntax, but causes a syntax error otherwise.
This code illustrates my problem:
class C
def >>(&block)
block.call("inside >>")
end
end
c = C.new
c.>> { |x| puts x } # outputs "inside >>"
#c >> { |x| puts x } # syntax error, if uncommented
This is the syntax error reported:
test.rb:10: syntax error, unexpected '|', expecting '}'
c >> { |x| puts x } # syntax error, if uncommented
^
test.rb:10: syntax error, unexpected tIDENTIFIER, expecting kDO or '{'
or '('
c >> { |x| puts x } # syntax error, if uncommented
^
Any pointers? Thanks.
it takes a block as its argument. It works if I invoke the redifined >>
operator using "." syntax, but causes a syntax error otherwise.
This code illustrates my problem:
class C
def >>(&block)
block.call("inside >>")
end
end
c = C.new
c.>> { |x| puts x } # outputs "inside >>"
#c >> { |x| puts x } # syntax error, if uncommented
This is the syntax error reported:
test.rb:10: syntax error, unexpected '|', expecting '}'
c >> { |x| puts x } # syntax error, if uncommented
^
test.rb:10: syntax error, unexpected tIDENTIFIER, expecting kDO or '{'
or '('
c >> { |x| puts x } # syntax error, if uncommented
^
Any pointers? Thanks.