# Why can not set value to instance variable of Class?

**URL:** <https://www.ruby-forum.com/t/why-can-not-set-value-to-instance-variable-of-class/195424>\
**Category:** Ruby\
**Created:** [September 23, 2010, 5:23am UTC](https://www.ruby-forum.com/t/why-can-not-set-value-to-instance-variable-of-class/195424 "2010-09-23T05:23:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![imelody](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e274bd/32.png) [@imelody](https://www.ruby-forum.com/u/imelody)\
**Post date:** [September 23, 2010, 5:23am UTC](https://www.ruby-forum.com/t/why-can-not-set-value-to-instance-variable-of-class/195424/1 "2010-09-23T05:23:03Z")

</div>

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  
}

---

<div class="post-metadata">

**Author:** ![imelody](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e274bd/32.png) [@imelody](https://www.ruby-forum.com/u/imelody)\
**Post date:** [September 23, 2010, 5:42am UTC](https://www.ruby-forum.com/t/why-can-not-set-value-to-instance-variable-of-class/195424/2 "2010-09-23T05:42:13Z")

</div>

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.
