From: R.. Kumar 1.9.1 OSX on 30 Jun 2010 07:11 /opt/local/lib/ruby1.9/1.9.1/pathname.rb:270: warning: `*' interpreted as argument prefix I keep getting this. I am including highline, sqlite3 and arrayfields in my code. I am using ruby -w inside my code. ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-darwin10] Mac OSX Intel (Snow leopard). I get this when running the examples in highline also. -- Posted via http://www.ruby-forum.com/.
From: Brian Candler on 30 Jun 2010 08:39 R.. Kumar 1.9.1 OSX wrote: > /opt/local/lib/ruby1.9/1.9.1/pathname.rb:270: warning: `*' interpreted > as argument prefix Can you post line 270 of that file, with a few lines of context? Can you replicate the problem standalone? e.g. #!/usr/bin/ruby19 -w require 'pathname' puts Pathname.new("/etc") This doesn't give any warning for me, but does it for you? If not, what's the smallest program you can make which shows the warning? -- Posted via http://www.ruby-forum.com/.
From: Josh Cheek on 30 Jun 2010 08:50 [Note: parts of this message were removed to make it a legal post.] On Wed, Jun 30, 2010 at 6:11 AM, R.. Kumar 1.9.1 OSX <sentinel1879(a)gmail.com > wrote: > /opt/local/lib/ruby1.9/1.9.1/pathname.rb:270: warning: `*' interpreted > as argument prefix > > > I keep getting this. I am including highline, sqlite3 and arrayfields in > my code. > > I am using ruby -w inside my code. > > ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-darwin10] > 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?)
From: Brian Candler on 30 Jun 2010 09:55 Josh Cheek wrote: > Note: can anyone explain to me what unary * is? It's just the "splat". AFAIK it's not really an operator and is not mapped to a method call; it's part of the language syntax. -- Posted via http://www.ruby-forum.com/.
From: R.. Kumar 1.9.1 OSX on 1 Jul 2010 01:48 Brian Candler wrote: > R.. Kumar 1.9.1 OSX wrote: >> /opt/local/lib/ruby1.9/1.9.1/pathname.rb:270: warning: `*' interpreted >> as argument prefix > > Can you post line 270 of that file, with a few lines of context? > > Can you replicate the problem standalone? e.g. > #!/usr/bin/ruby19 -w require 'pathname' The above is enough to give the error. 1. I do not want to fix the problem in my own copy of ruby 1.9 and have it keep returning when i upgrade versions, or have others get it. 2. While googling, I found that the problem was fixed in 1.8.x but perhaps not in 1.9. Is that the case ? The code in pathname.rb is 259 # Return a pathname which is substituted by String#sub. 260 def sub(pattern, *rest, &block) 261 if block 262 path = @path.sub(pattern, *rest) {|*args| 263 begin 264 old = Thread.current[:pathname_sub_matchdata] 265 Thread.current[:pathname_sub_matchdata] = $~ 266 eval("$~ = Thread.current[:pathname_sub_matchdata]", block.binding) 267 ensure 268 Thread.current[:pathname_sub_matchdata] = old 269 end 270 yield *args 271 } 272 else 273 path = @path.sub(pattern, *rest) 274 end 275 self.class.new(path) 276 end -- Posted via http://www.ruby-forum.com/.
|
Next
|
Last
Pages: 1 2 3 Prev: Taking out text between symbols and joining together Next: optparser question |