Rubycookbook


(Bil Kleb) #1

Any news on http://www.rubycookbook.org/ availability?

···


Bil


(Serg Koren) #2

Hi,
I’m just trying to learn Ruby and am wondering what the proper way of
having a composite class (not a mixin). I’d like to have one class be
an instance variable of another class.

Class X
def myX
End
End

Class Y
myNest = X::new

def myY
end
end

myObject = Y::new

myObject::myNest.myX # <------ gives an error

What’s the proper way of doing this in Ruby?

Thanks,
S


(Armin Roehrl) #3

if webspace is the problem, we can host it for free here,
or maybe the best would be to host it on sf.net

Ciao,
A

···

Am Dienstag, 11. Juni 2002 15:56 schrieben Sie:

Any news on http://www.rubycookbook.org/ availability?


(Ned Konz) #4

Hi,
I’m just trying to learn Ruby and am wondering what the proper
way of having a composite class (not a mixin). I’d like to have
one class be an instance variable of another class.

Do you mean that you want an instance of one class be an instance
variable of another class? This is done all the time.

class X
def myX
end
end

class Y
def initialize
@myX = X.new
end
attr_reader :myX
end

Class Y
myNest = X::new

This would be a local variable, not an instance variable.

···

On Tuesday 11 June 2002 07:06 am, Serg Koren wrote:


Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE


(Kyle Rawlins) #5

myNest in your code isn’t visable externally to the area of the class (it is I
guess a local variable). If you want it to be a constant (in which case it
would be visible) capitalize the first character of its name. If you want it
to be an instance variable do this:

class Y
attr_reader :myNest
def initialize()
@myNest = X.new
end
end

then the call that you have above should work.

-kyle

···

On Tue, Jun 11, 2002 at 11:06:34PM +0900, Serg Koren wrote:

Class X
def myX
End
End

Class Y
myNest = X::new

def myY
end
end

myObject = Y::new

myObject::myNest.myX # <------ gives an error

What’s the proper way of doing this in Ruby?


http://mas.cs.umass.edu/~rawlins

the pieces of the puzzle are waiting the water of the dark boats