Local variables and functions

Discussion in 'Ruby' started by Robert Mannl, May 30, 2005.

  1. Robert Mannl

    Robert Mannl Guest

    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
    Robert Mannl, May 30, 2005
    #1
    1. Advertising

  2. Robert Mannl

    Robert Mannl Guest

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


    Cheers,
    R
    Robert Mannl, May 30, 2005
    #2
    1. Advertising

  3. Robert Mannl

    Kent Sibilev Guest

    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 <> wrote:
    > Hi!
    >=20
    > I got one question. While I was coding a method earlier today, and that
    > method had lots of local variables, I was thinking:
    >=20
    > "What happens when I introduce a new method sometime in the future,
    > while adding features to my program? That may lead to name clashes"
    >=20
    > 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..
    >=20
    > Am I missing something here?
    >=20
    > Thanks :)
    >=20
    >=20
    > Rob
    >=20
    > 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
    >=20
    >
    Kent Sibilev, May 30, 2005
    #3
  4. Robert Mannl

    Eric Mahurin Guest

    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 <> 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 <> 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/resources/
    Eric Mahurin, May 30, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Razvan
    Replies:
    11
    Views:
    895
    Andrew Thompson
    Jul 17, 2004
  2. Xiangliang Meng
    Replies:
    1
    Views:
    1,577
    Victor Bazarov
    Jun 21, 2004
  3. Sullivan WxPyQtKinter
    Replies:
    10
    Views:
    639
    Antoon Pardon
    Nov 8, 2007
  4. Tammo Tjarks
    Replies:
    2
    Views:
    276
    Tammo Tjarks
    Sep 13, 2007
  5. king
    Replies:
    2
    Views:
    158
    Tad McClellan
    Jun 27, 2006
Loading...

Share This Page