ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
Re: Subclassing Struct.new
by mental other posts by this author
Feb 28 2006 7:13AM messages near this date
Re: Subclassing Struct.new | Re: Subclassing Struct.new
Quoting chiaro scuro <kiaroskuro@[...].com> :

>  I guess that in principle when you see an '=', you could lookup a
>  'name=' method before deciding that it is a local var assignment
>  rather than a method call.
> 
>  I also understand that there will be perfromance issues with
>  that.
> 
>  did I miss something?

In Ruby's grammar, expressions containing a name parse differently
depending on whether that name is a variable or a method.

Whatever rule is used has to be able to distinguish between the two
at parse-time; you can't rely on run-time information.

So, the current parsing rule is: "If you see an assignment to a bare
name, that name means a variable until the end of the block/method. 
Until then it means a method call."

e.g.:

 def foo
   n # method
 end

 def bar
   n = 3
   n # variable
 end

 def baz
   n # method
   n = 3
   n # variable
 end

Note that it doesn't matter if the assignment is actually performed,
just that the parser sees it:

 def hoge
   n # method
   if false
     n = 3
   end
   n # variable
 end

(uninitialized variables are nil)

-mental
Thread:
Minkoo Seo
Chiaro Scuro
Minkoo Seo
Yukihiro Matsumoto
Mark Wilden
Markus Werner
Chiaro Scuro
Minkoo Seo
Minkoo Seo
Hal Fulton
mental
Ross Bamford
mental
Ross Bamford
Chiaro Scuro
Ross Bamford
Chiaro Scuro
Minkoo Seo
Chiaro Scuro
mental
Chiaro Scuro
mental
Yukihiro Matsumoto
Caleb Clausen
Yukihiro Matsumoto
Caleb Clausen
MenTaLguY
Yukihiro Matsumoto
gwtmp01
Chiaro Scuro
mental
Chiaro Scuro
mental
Logan Capaldo
Pit Capitain

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved