Greg Buchholz wrote:
> I'm a Ruby novice working my way through the pickaxe book, and I've got
> what should be an easy syntax question.  On page 84 of chapter 6, the
> authors present the following program...

[... program elided ...]

> ....Since everything is an object (right?), 

Heh!  Well, almost.  I like to say that everything you can bind to a 
variable is an object.  The problem is that you are playing games with 
syntax.  You are trying to represent the operator of an expression with 
an expression.  Since the operator itself is not a full expression, you 
can't jam an expression in that place.  You would get the same error 
from (the much simpler):

    n (*) number

If you want to dynamically choose the operation, then "send" is your 
friend.  For example:

    n.send("*", number)

will work.  Fixing your example to use send would be:

    puts((1..10).collect{|n| n.send((times =~ /^t/ ? "*" : "+"), number) 
}.join(","))

--
-- Jim Weirich




-- 
Posted via http://www.ruby-forum.com/.