Calling a setter method in self (without self.)

Discussion in 'Ruby' started by Tapio Kelloniemi, Mar 12, 2007.

  1. Hi

    I'm writing a code where it would be desirable to be able to call setter
    methods in self without having to specify self explicitly. Like:
    x = 0 # calls self.x=, does not assign to a local variable

    In Ruby 1.6 this was impossible. Is this still the case in 1.8 and 1.9?
    I believe it is, but would like to be sure.

    Thanks!

    --
    Tapio
    Tapio Kelloniemi, Mar 12, 2007
    #1
    1. Advertising

  2. Tapio Kelloniemi

    Guest

    On Tue, 13 Mar 2007, Tapio Kelloniemi wrote:

    > Hi
    >
    > I'm writing a code where it would be desirable to be able to call setter
    > methods in self without having to specify self explicitly. Like:
    > x = 0 # calls self.x=, does not assign to a local variable
    >
    > In Ruby 1.6 this was impossible. Is this still the case in 1.8 and 1.9?
    > I believe it is, but would like to be sure.
    >
    > Thanks!
    >
    > --
    > Tapio


    a work around...

    harp:~ > cat a.rb
    require 'rubygems'
    require 'attributes'

    attribute :x

    x 42

    p x

    harp:~ > ruby a.rb
    42

    cheers.

    -a
    --
    be kind whenever possible... it is always possible.
    - the dalai lama
    , Mar 12, 2007
    #2
    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. Martin Kess
    Replies:
    2
    Views:
    1,100
  2. Ralf W. Grosse-Kunstleve
    Replies:
    16
    Views:
    552
    Lonnie Princehouse
    Jul 11, 2005
  3. Replies:
    7
    Views:
    139
  4. Paul

    self and private setter

    Paul, Dec 18, 2007, in forum: Ruby
    Replies:
    7
    Views:
    128
    Rick DeNatale
    Dec 19, 2007
  5. Le Wang
    Replies:
    2
    Views:
    799
    Knut Lickert
    Aug 13, 2011
Loading...

Share This Page