[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: how to get the name of parent object inside child object

Raffaele Tesi

2/1/2008 11:04:00 AM

i don't know exactly what you mean, but...
Given object x try:

puts x.class.superclass
--
Posted via http://www.ruby-....

3 Answers

Pokkai Dokkai

2/1/2008 2:17:00 PM

0

Raffaele Tesi wrote:
> i don't know exactly what you mean, but...
> Given object x try:
>
> puts x.class.superclass

class Cycle
@brand="something"
def initialize
end
end
class Wheel
@brand
def option
Cycle.new
end
end

> w=Wheel.new
> @brand --->nil
> w.option
> @brand --->"something"


i need a requirement like above one example.

should not passing any arguments to child object(w.option)
global variable is not allowed.
--
Posted via http://www.ruby-....

Raffaele Tesi

2/1/2008 3:14:00 PM

0

# something like this?

class Cycle
attr_accessor :brand
def initialize
@brand="something"
end
end
class Wheel
def option
Cycle.new
end
end

w=Wheel.new
puts w.option.brand
--
Posted via http://www.ruby-....

Pokkai Dokkai

2/2/2008 5:29:00 AM

0

thank for the quick reply

sorry i wrote wrong explanation
this is my correct explanation


class Cycle
@brand=nil
def initialize
end
end
class Wheel
@brand="something"
def option
Cycle.new
end
end

> w=Wheel.new
> w.brand --->something
> c=Cycle.new
> c.brand --->nil

> w.option.brand --->something

any idea ?
--
Posted via http://www.ruby-....