Re: Strange instance variable behaviour

  • From: Ola Bini <ola.bini@gmail.com>
  • To: Hendrik Volkmer <solaris@sundevil.de>
  • Cc: users@ioke.kenai.com
  • Subject: Re: Strange instance variable behaviour
  • Date: Thu, 01 Jan 2009 16:39:05 +0100
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=xzLvd9yQxMJzjM0IbQ4AjwHVDwKPs94Nuj9G8gWbGyWYWjZTUTsQk7jG6ufU0j2e8R XAxIwIw5Fgc1QCgtxRz1PkS99KCpVM/dvH+ZPEvdEG5GPunbNxxRUEa9Nvtcf96KtP+Q +gslRXdxgNxaeVlXXBfrSA+DyCpvJqnrSE1F4=

Hendrik Volkmer wrote:
Hi there,

I've been playing around with ioke a little bit and came across this behaviour which I don't quite understand:

---- start code ---
use("ispec")

Dog = Origin mimic
Dog food = []
Dog name = ""

Dog set_name = method(name,
  self name = name
)

Dog feed = method("feeds the dog", food_item,
  self food << food_item
 )

Hi,

The behavior you're seeing is because the name is set above. That will set the name of the dog on the new instance. The feeding process in contrast just adds an element to an existing list - this list comes from the Dog mimic, and is thus global for all of them.

Cheers

--
Ola Bini (http://olabini.com) JRuby Core Developer
Developer, ThoughtWorks Studios (http://studios.thoughtworks.com)
Practical JRuby on Rails (http://apress.com/book/view/9781590598818)

"Yields falsehood when quined" yields falsehood when quined.




Strange instance variable behaviour

Hendrik Volkmer 01/01/2009

Re: Strange instance variable behaviour

Ola Bini 01/01/2009

Message not available

Re: Strange instance variable behaviour

T W 01/02/2009

Re: Strange instance variable behaviour

Ola Bini 01/02/2009
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close