On Wed, Jun 30, 2010 at 6:11 AM, R… Kumar 1.9.1 OSX
<[email protected]
wrote:
Mac OSX Intel (Snow leopard).
I get this when running the examples in highline also.
Posted via http://www.ruby-forum.com/.
It is a warning to let you know that it considers what you typed to be
ambiguous, and it is concerned that the way it interprets your code may
not
be what you intended
ary = [ 10 , 20 , 30 ]
ary.first * 2 # => 20
(ary.first) * 2 # => 20
(ary.first) * (2) # => 20
(ary.first * 2) # => 20
(ary.first * 2) # => 20
ary.first.*(2) # => 20
ary.first 2 # => [10, 20] # !> *' interpreted as argument prefix ary.first *[2] # => [10, 20] # !>
’ interpreted as argument
prefix
ary.first(*[2]) # => [10, 20]
ary.first(*2) # => [10, 20]
ary.first(2) # => [10, 20]
ary.first 2 # => [10, 20]
In particular notice the first from each set
ary.first * 2 # => 20
ary.first 2 # => [10, 20] # !> `’ interpreted as argument prefix
In your particular case, it sees:
Return a pathname which is substituted by String#sub.
def sub(pattern, *rest, &block)
if block
path = @path.sub(pattern, *rest) {|*args|
begin
old = Thread.current[:pathname_sub_matchdata]
Thread.current[:pathname_sub_matchdata] = $~
eval(“$~ = Thread.current[:pathname_sub_matchdata]”,
block.binding)
ensure
Thread.current[:pathname_sub_matchdata] = old
end
yield *args
}
else
path = @path.sub(pattern, *rest)
end
self.class.new(path)
end
and it is worried about the ambiguity of yield *args (get the results of
the
block and multiply it by the variable named args vs take the variable
args,
invoke the * on it to turn it into a sort of variable argument list, and
then pass those arguments to in to the block)
Anyway, if it bothers you, you can go put parens around it so it becomes
yield(*args) and is not ambiguous. But you don’t need to worry about it,
look where it got those args from:
path = @path.sub(pattern, *rest) {|*args|
So it is recursively invoking itself, passing the args through the
calls,
clearly the author did want it to be interpreted this way.
Note: can anyone explain to me what unary * is? I looked in the Pickaxe
page
333, and don’t see it listed with the other operators. I tried defining
@
as an instance method, and I couldn’t define it. I tried locating the
method
2.method('@') and it was undefined. I tried looking at parse.y, and
found
tSTAR mlhs_node { $$ = NEW_MASGN(0, $2); } which I suspect defines the
interpreter match for it, but couldn’t figure out how to then determine
what
happens with this. What is it / where did it come from (is it an
object?)