Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Why can not set value to instance variable of Class?

Reply
Thread Tools

Why can not set value to instance variable of Class?

 
 
iMelody Ooo
Guest
Posts: n/a
 
      09-23-2010
class ParaList
attr_reader:classname
attr_writeraralist
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/.

 
Reply With Quote
 
 
 
 
Tony Arcieri
Guest
Posts: n/a
 
      09-23-2010
[Note: parts of this message were removed to make it a legal post.]

You've defined an attr_writer for aralist, 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 <(E-Mail Removed)> wrote:

> class ParaList
> attr_reader:classname
> attr_writeraralist
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why can't an instance instantiated within a class method access aprotected instance method? Greg Hauptmann Ruby 9 06-16-2008 10:16 AM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Can you set a class instance's attributes to zero by setting the instance to zero? Gerard Flanagan Python 3 11-19-2005 06:58 PM
Problem when subclass instance changes base class instance variable Gerry Sutton Python 1 04-16-2005 06:06 AM
accessing class instance variable from instance method David Garamond Ruby 5 06-08-2004 02:26 PM



Advertisments