On Mon, Jun 19, 2006 at 06:06:37PM +1000, david wrote:
> You were right, but as you can see below, the syntax can still be picky
> even if it IS ruby ;-) .... I had tried the first version but not the
> second one (yours):
>
> irb(main):048:0> y.(length-1).times do puts "blah" end
> SyntaxError: compile error
> (irb):48: syntax error
> y.(length-1).times do puts "blah" end
That should be (y.length-1).times { puts "blah" }
The problem with y.(length-1).times is that (length-1) gets evaluated first,
but you can't do dynamic method names that way, so everything will blow up.
Instead, when you do (y.length-1).times, y.length-1 gets evaluated by the
normal precedence rules, so you have (y.length)-1 then you get an integer
out of that, which can then have .times called on it and everything's hunky
dory.
- Matt
_______________________________________________
coders mailing list
[email protected]
http://lists.slug.org.au/listinfo/coders