Google Groups Home
Help | Sign in
Message from discussion Container wont contain! (noob question)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Extreme Noob  
View profile
 More options May 11, 4:22 pm
Newsgroups: comp.lang.ruby
From: Extreme Noob <bengaly...@hotmail.com>
Date: Sun, 11 May 2008 15:22:21 -0500
Local: Sun, May 11 2008 4:22 pm
Subject: Container wont contain! (noob question)
Here I want to change Class1's var2 to equal 2. Now, I can do this by..
"object.m_container.container1 = Class1.new(2)", but I want to do it
with "object.change_me = 2"
Point is I want to change that variable by simply using a number, as
apposed to xxx.new(arg).
Why wont object.change_me =2 work?

(sorry if this seems confusing or silly)

The following is a highly simplified representation of my current
problem....

#******************************************************************

class Class1

    def initialize(aVar)
        @var = aVar
        @var2 = nil
        if @var == 1 then @var2 = 1 elsif @var == 2 then @var2 = 2 end
    end
end

class Class2
      attr_accessor :container1

      def initialize(container1)
        @container1 = container1
           end
end

class M_class
  attr_accessor(:m_container,:change_me)

  def initialize
    @m_container = Class2.new(Class1.new(change_me) )
  end

        def change_me
               @change_me = 1
        end
end

object = M_class.new

#object.m_container.container1 = Class1.new(2)  <--- currently doing it
like this

#object.change_me = 2   <----- want to do it like this (or something as
easy)

p object

#*******************************************************
--
Posted via http://www.ruby-forum.com/.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google