Why can not set value to instance variable of Class?

Discussion in 'Ruby' started by iMelody Ooo, Sep 23, 2010.

  1. iMelody Ooo

    iMelody Ooo Guest

    class ParaList
    attr_reader:classname
    attr_writer:paralist
    def initialize(name)
    @classname = name
    @paralist = Hash.new
    end
    end

    $cellparalist = ParaList.new("AAA")

    def MmlParse.addpara(paraclass,mo,mmlparalist)
    a = Hash.new
    a = paraclass.paralist
    #Error:in `addpara': undefined method `paralist' for #<ParaList:0xc6eff5
    b = Hash.new
    b["AAA"]=100;
    a = b
    }
    --
    Posted via http://www.ruby-forum.com/.
     
    iMelody Ooo, Sep 23, 2010
    #1
    1. Advertising

  2. iMelody Ooo

    Tony Arcieri Guest

    [Note: parts of this message were removed to make it a legal post.]

    You've defined an attr_writer for :paralist, but need an attr_reader for it
    in order for the method you are calling to be defined. You probably want to
    change attr_writer to attr_reader, or use attr_accessor if you really want
    it to still be writable. attr_writer defines a separate method called
    paralist=. You can call that method using paraclass.paralist = foobar.

    On Wed, Sep 22, 2010 at 9:23 PM, iMelody Ooo <> wrote:

    > class ParaList
    > attr_reader:classname
    > attr_writer:paralist
    > def initialize(name)
    > @classname = name
    > @paralist = Hash.new
    > end
    > end
    >
    > $cellparalist = ParaList.new("AAA")
    >
    > def MmlParse.addpara(paraclass,mo,mmlparalist)
    > a = Hash.new
    > a = paraclass.paralist
    > #Error:in `addpara': undefined method `paralist' for #<ParaList:0xc6eff5
    > b = Hash.new
    > b["AAA"]=100;
    > a = b
    > }
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >



    --
    Tony Arcieri
    Medioh! A Kudelski Brand
     
    Tony Arcieri, Sep 23, 2010
    #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. Gerry Sutton
    Replies:
    1
    Views:
    544
    Peter Otten
    Apr 16, 2005
  2. Gerard Flanagan
    Replies:
    3
    Views:
    448
    Terry Hancock
    Nov 19, 2005
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,008
    Smokey Grindel
    Dec 2, 2006
  4. David Garamond
    Replies:
    5
    Views:
    252
    Ara.T.Howard
    Jun 8, 2004
  5. Greg Hauptmann
    Replies:
    9
    Views:
    251
    Loren Segal
    Jun 16, 2008
Loading...

Share This Page