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. Advertisements

  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. Advertisements

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. Sridhar R
    Replies:
    14
    Views:
    1,726
    =?iso-8859-1?Q?Fran=E7ois?= Pinard
    Feb 10, 2004
  2. Gerry Sutton
    Replies:
    1
    Views:
    720
    Peter Otten
    Apr 16, 2005
  3. Gerard Flanagan
    Replies:
    3
    Views:
    664
    Terry Hancock
    Nov 19, 2005
  4. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    1,347
    Mark Rae
    Dec 21, 2006
  5. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,795
    Smokey Grindel
    Dec 2, 2006
  6. Martin P. Hellwig
    Replies:
    1
    Views:
    496
    Martin P. Hellwig
    Mar 26, 2010
  7. David Garamond
    Replies:
    5
    Views:
    435
    Ara.T.Howard
    Jun 8, 2004
  8. Greg Hauptmann
    Replies:
    9
    Views:
    473
    Loren Segal
    Jun 16, 2008
Loading...