Yes, roughly speaking that's what I was saying. It does that scan for lvalues on parse. On 14 Jan 2016 12:01 pm, "Ryan Bigg" <[email protected]> wrote:
> It won't ever do self.send(:x=, 3). x = 3 is always a local variable > assignment. > > > On 14 Jan 2016, at 11:52, Clifford Heath <[email protected]> > wrote: > > > >> On 14 Jan 2016, at 9:19 AM, Simon Russell <[email protected]> wrote: > >> I'd say this "feature" probably has no useful purpose; I can't imagine > a language designer deliberately putting it in. It's more likely to cause > bugs than joy. > >> I'm not certain, but I'm fairly your "unintended parser functionality" > is heading in the right direction. > > > > No. I think it’s a necessary feature of the Ruby syntax. When Ruby sees > “x = 3”, it needs to decide whether you want an assignment to a local > variable, or “self.send(:x=, 3)”. > > > > So it looks around the local scope for clues about what you meant, and > when it decides that a word is the name of a local variable, it treats it > that way throughout the function. > > > > Clifford Heath. > > > >> From memory working on a Ruby compiler, Ruby allocates local variables > before execution, but doesn't mark where they become "real". So they're > essentially real from the start, and get assigned a default value of nil. > It makes the whole thing easier to build; it's kind of a shortcut. > >> > >> So, moral of this story is... Don't assign things twice? Makes for a > better design anyway! :) > >> > >> On Thu, Jan 14, 2016 at 5:35 AM, Gareth Townsend < > [email protected]> wrote: > >> Rubocop has a linter for shadowing variables; > >> > >> > http://www.rubydoc.info/github/bbatsov/rubocop/Rubocop/Cop/Lint/ShadowingOuterLocalVariable > >> > >> Gareth Townsend > >> http://www.garethtownsend.info > >> > >>> On 13 Jan 2016, at 22:00, David Parry <[email protected]> > wrote: > >>> > >>> Shadowing variables, which is effectively what you’ve done with > “misspelt_argument”, is pretty-much always a bad idea in most languages. > >>> > >>> In functional languages, it’s mostly impossible to do without the > compiler complaining, and for very good reasons, one of which you’ve > pointed out. > >>> > >>> I suspect that tools like RuboCop would probably pick this sort of > abomination up. Anyone know if that’s the case? > >>> > >>> > >>> > >>>> On 13 Jan 2016, at 8:41 PM, Tom Hale <[email protected]> wrote: > >>>> > >>>> It took some debugging to come across this one: > >>>> > >>>> irb(main):043:0> w > >>>> NameError: undefined local variable or method `w' for main:Object > >>>> from (irb):43 > >>>> from /home/ravi/.rbenv/versions/2.2.3/bin/irb:11:in `<main>' > >>>> irb(main):044:0> w = w > >>>> => nil > >>>> irb(main):045:0> > >>>> > >>>> Yeah, right, so what? > >>>> > >>>> It leads to "find the nil" fun-hunts in cases such as: > >>>> > >>>> irb(main):057:0> mispelt_argument = > Array(mispelt_argument).flatten.uniq.map(&:name) > >>>> => [] > >>>> > >>>> Are there any cases in which this "feature" is actually useful, or is > it an unintended parser functionality? > >>>> > >>>> Tom > >>>> > >>>> -- > >>>> You received this message because you are subscribed to the Google > Groups "Ruby or Rails Oceania" group. > >>>> To unsubscribe from this group and stop receiving emails from it, > send an email to [email protected]. > >>>> To post to this group, send email to [email protected]. > >>>> Visit this group at https://groups.google.com/group/rails-oceania. > >>>> For more options, visit https://groups.google.com/d/optout. > >>> > >>> -- > >>> You received this message because you are subscribed to the Google > Groups "Ruby or Rails Oceania" group. > >>> To unsubscribe from this group and stop receiving emails from it, send > an email to [email protected]. > >>> To post to this group, send email to [email protected]. > >>> Visit this group at https://groups.google.com/group/rails-oceania. > >>> For more options, visit https://groups.google.com/d/optout. > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups "Ruby or Rails Oceania" group. > >> To unsubscribe from this group and stop receiving emails from it, send > an email to [email protected]. > >> To post to this group, send email to [email protected]. > >> Visit this group at https://groups.google.com/group/rails-oceania. > >> For more options, visit https://groups.google.com/d/optout. > >> > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups "Ruby or Rails Oceania" group. > >> To unsubscribe from this group and stop receiving emails from it, send > an email to [email protected]. > >> To post to this group, send email to [email protected]. > >> Visit this group at https://groups.google.com/group/rails-oceania. > >> For more options, visit https://groups.google.com/d/optout. > > > > -- > > You received this message because you are subscribed to the Google > Groups "Ruby or Rails Oceania" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to [email protected]. > > To post to this group, send email to [email protected]. > > Visit this group at https://groups.google.com/group/rails-oceania. > > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby or Rails Oceania" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/rails-oceania. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/rails-oceania. For more options, visit https://groups.google.com/d/optout.
