[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Local variables and functions

Robert Mannl

5/30/2005 7:14:00 PM

Hi!

I got one question. While I was coding a method earlier today, and that
method had lots of local variables, I was thinking:

"What happens when I introduce a new method sometime in the future,
while adding features to my program? That may lead to name clashes"

For example, lets say I use the local variable "ids" in a method - as
soon as I introduce a method called ids into the class, or a mixin of
that class - whatever - the program breaks! And it's not easy to avoid
that..

Am I missing something here?

Thanks :)


Rob

PS: btw I'm getting some spam to my brand new email address (this one
I'm using) - I searched the web for my email address and an archive of
this Ruby mailing list -- shouldn't that be avoided? Posting emails on
the web I mean --- it's not a big problem though, as this email is not
very important. Just curious


3 Answers

Robert Mannl

5/30/2005 7:38:00 PM

0

Nevermind -- I forgot local variables have precedence over method calls
-- if I understood it correctly


Cheers,
R


Kent Sibilev

5/30/2005 7:38:00 PM

0

Your local variables always hide methods with the same name. In order
to call a method instead of accessing a variable you should provide
some hints to Ruby like use parentheses () or access a method
explicitly through self.method_name.

Kent.

On 5/30/05, Robert Mannl <ro@cayoparaiso.com> wrote:
> Hi!
>
> I got one question. While I was coding a method earlier today, and that
> method had lots of local variables, I was thinking:
>
> "What happens when I introduce a new method sometime in the future,
> while adding features to my program? That may lead to name clashes"
>
> For example, lets say I use the local variable "ids" in a method - as
> soon as I introduce a method called ids into the class, or a mixin of
> that class - whatever - the program breaks! And it's not easy to avoid
> that..
>
> Am I missing something here?
>
> Thanks :)
>
>
> Rob
>
> PS: btw I'm getting some spam to my brand new email address (this one
> I'm using) - I searched the web for my email address and an archive of
> this Ruby mailing list -- shouldn't that be avoided? Posting emails on
> the web I mean --- it's not a big problem though, as this email is not
> very important. Just curious
>
>


Eric Mahurin

5/30/2005 9:10:00 PM

0

Last I checked that won't help in Ruby 1.9 - local variables
always hide methods of the same name, even with the (). But,
that change (callable objects) may be reverted.

--- Kent Sibilev <ksruby@gmail.com> wrote:

> Your local variables always hide methods with the same name.
> In order
> to call a method instead of accessing a variable you should
> provide
> some hints to Ruby like use parentheses () or access a method
> explicitly through self.method_name.
>
> Kent.
>
> On 5/30/05, Robert Mannl <ro@cayoparaiso.com> wrote:
> > Hi!
> >
> > I got one question. While I was coding a method earlier
> today, and that
> > method had lots of local variables, I was thinking:
> >
> > "What happens when I introduce a new method sometime in the
> future,
> > while adding features to my program? That may lead to name
> clashes"
> >
> > For example, lets say I use the local variable "ids" in a
> method - as
> > soon as I introduce a method called ids into the class, or
> a mixin of
> > that class - whatever - the program breaks! And it's not
> easy to avoid
> > that..
> >
> > Am I missing something here?
> >
> > Thanks :)
> >
> >
> > Rob
> >
> > PS: btw I'm getting some spam to my brand new email address
> (this one
> > I'm using) - I searched the web for my email address and an
> archive of
> > this Ruby mailing list -- shouldn't that be avoided?
> Posting emails on
> > the web I mean --- it's not a big problem though, as this
> email is not
> > very important. Just curious
> >
> >
>
>




__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new Resources site
http://smallbusiness.yahoo.com/...