[ruby] #47: Cannot pass a :symbol directly as a named parameter
#47: Cannot pass a :symbol directly as a named parameter ----------------------------+----------------------------------------------- Reporter: cremes@mac.com | Owner: lsansonetti@apple.com Type: defect | Status: new Priority: minor | Milestone: MacRuby 0.2 Component: MacRuby | Keywords: symbol named keyed parameter ----------------------------+----------------------------------------------- Here's an example to illustrate. Code was tested against the "testing" branch from 20080405. class A def initialize @h = {} end def setValue(val, forKey:key) @h[key] = val end end a = A.new a.setValue("triple", forKey::three) # fails a.setValue("triple", forKey: :three) # succeeds three = :three a.setValue("triple", forKey:three) # succeeds a.setValue("triple", forKey:'three'.to_sym) # succeeds When using the #:: syntax the parser mistakenly views it as an attempt to access the method #forKey on Object. At minimum it should probably throw a more useful error message and perhaps suggest adding a space between colons. -- Ticket URL: <http://trac.macosforge.org/projects/ruby/ticket/47> ruby <http://ruby.macosforge.org/>
#47: Cannot pass a :symbol directly as a named parameter ------------------------------------------+--------------------------------- Reporter: cremes@mac.com | Owner: lsansonetti@apple.com Type: defect | Status: new Priority: minor | Milestone: MacRuby 0.2 Component: MacRuby | Resolution: Keywords: symbol named keyed parameter | ------------------------------------------+--------------------------------- Comment (by lsansonetti@apple.com): Currently, {{{a.setValue("triple", forKey::three}}} produces {{{undefined local variable or method `forKey' for main:Object (NameError)}}}. I wonder if we should do something. {{{forKey::three}}} is a perfectly valid syntax (it basically means {{{forKey.three}}}). {{{
123.to_s => "123" 123::to_s => "123" }}}
In that case it would mean: send {{{#setValue}}} with 2 regular (not- named) arguments: {{{"triple"}}} and the result of {{{forKey::three}}}. -- Ticket URL: <http://trac.macosforge.org/projects/ruby/ticket/47#comment:1> ruby <http://ruby.macosforge.org/>
#47: Cannot pass a :symbol directly as a named parameter ------------------------------------------+--------------------------------- Reporter: cremes@mac.com | Owner: lsansonetti@apple.com Type: defect | Status: new Priority: minor | Milestone: MacRuby 0.2 Component: MacRuby | Resolution: Keywords: symbol named keyed parameter | ------------------------------------------+--------------------------------- Comment (by cremes@mac.com): I agree the syntax is valid but it does confuse the issue for named parameters. Right now the warning is a bit too arcane. If it printed what it does now *in addition to* an extra sentence regarding named parameters and how to use them properly, then I think it would be an improvement. Thanks for working on this. I'm doing a presentation on it for the Chicago Cocoa user's group tomorrow night and ran across this while putting my slideshow together. -- Ticket URL: <http://trac.macosforge.org/projects/ruby/ticket/47#comment:2> ruby <http://ruby.macosforge.org/>
#47: Cannot pass a :symbol directly as a named parameter ------------------------------------------+--------------------------------- Reporter: cremes@mac.com | Owner: lsansonetti@apple.com Type: defect | Status: new Priority: minor | Milestone: MacRuby 0.2 Component: MacRuby | Resolution: Keywords: symbol named keyed parameter | ------------------------------------------+--------------------------------- Comment (by lsansonetti@apple.com): I do agree that we need better error reporting in this case, let's try to fix that. Good to know that you're presenting about it, good luck :-) -- Ticket URL: <http://trac.macosforge.org/projects/ruby/ticket/47#comment:3> ruby <http://ruby.macosforge.org/>
#47: Cannot pass a :symbol directly as a named parameter ------------------------------------------+--------------------------------- Reporter: cremes@mac.com | Owner: lsansonetti@apple.com Type: defect | Status: new Priority: minor | Milestone: MacRuby 1.0 Component: MacRuby | Resolution: Keywords: symbol named keyed parameter | ------------------------------------------+--------------------------------- Changes (by lsansonetti@apple.com): * milestone: MacRuby 0.2 => MacRuby 1.0 -- Ticket URL: <http://ruby.macosforge.org/trac/ticket/47#comment:4> macruby <http://ruby.macosforge.org/>
participants (2)
-
macruby
-
ruby