Why can not set value to instance variable of Class?

I

iMelody Ooo

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
}
 
T

Tony Arcieri

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

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
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top