[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Inheritance

Mickael Veovis

2/15/2008 10:59:00 AM

Hello,

I have this class :

class A
def toto
puts "tttt"
end
end


class B < A
def tata

end
end

I would like to now how in B.tata I can invoke, I can call the method
toto of A.

Thanks for your reply....
--
Posted via http://www.ruby-....

8 Answers

Jari Williamsson

2/15/2008 11:09:00 AM

0

Mickael Veovis wrote:
> Hello,
>
> I have this class :
>
> class A
> def toto
> puts "tttt"
> end
> end
>
>
> class B < A
> def tata
>
> end
> end
>
> I would like to now how in B.tata I can invoke, I can call the method
> toto of A.
>
> Thanks for your reply....

If I understand your question correctly:

b = B.new
b.toto

or:

B.new.toto


Best regards,

Jari Williamsson

Codeblogger

2/15/2008 11:10:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

class B < A
def tata
toto
end
end

Kind regards,
Nicolai

Jari Williamsson

2/15/2008 11:13:00 AM

0

I wrote:

> If I understand your question correctly:

Well, I probably misunderstood your it the first time around ;-)

Here's probably what you were looking for:

class B < A
def tata
toto
end
end

and then:

b = B.new
b.tata

or:

B.new.tata

Mickael Veovis

2/15/2008 11:18:00 AM

0

Sorry, but I make a mistake my class are :

class A
def toto
puts "tttt"
end
end


class B < A
def toto
puts "mmmmm"
end

def tata

end
end

And I would like in B.tata to call the method toto of A.
--
Posted via http://www.ruby-....

Sebastian Hungerecker

2/15/2008 1:18:00 PM

0

Mickael Rouvier wrote:
> class A
> =C2=A0def toto
> =C2=A0 =C2=A0 puts "tttt"
> =C2=A0end
> end
>
>
> class B < A
> =C2=A0 def toto
> =C2=A0 =C2=A0 =C2=A0puts "mmmmm"
> =C2=A0 end
>
> =C2=A0 def tata
>
> =C2=A0 end
> end
>
> And I would like in B.tata to call the method toto of A.

def tata
A.instance_method(:toto).bind(self).call
end

HTH,
Sebastian
=2D-=20
Jabber: sepp2k@jabber.org
ICQ: 205544826

Karl-Heinz Wild

2/15/2008 1:31:00 PM

0

On 15.02.2008, at 14:17, Sebastian Hungerecker wrote:

> Mickael Rouvier wrote:
>> class A
>> def toto
>> puts "tttt"
>> end
>> end
>>
>>
>> class B < A
>> def toto
>> puts "mmmmm"
>> end
>>
>> def tata
>>
>> end
>> end
>>
>> And I would like in B.tata to call the method toto of A.

class A
def toto
puts "tttt"
end
end

class B < A
alias :totoo :toto
def toto
puts "mmmm"
end
end

b = B.new
b.toto
b.totoo

- Karl-Heinz

Karl-Heinz Wild

2/15/2008 1:34:00 PM

0

On 15.02.2008, at 14:30, Karl-Heinz Wild wrote:

> On 15.02.2008, at 14:17, Sebastian Hungerecker wrote:
>
>> Mickael Rouvier wrote:
>>> class A
>>> def toto
>>> puts "tttt"
>>> end
>>> end
>>>
>>>
>>> class B < A
>>> def toto
>>> puts "mmmmm"
>>> end
>>>
>>> def tata
>>>
>>> end
>>> end
>>>
>>> And I would like in B.tata to call the method toto of A.
>
> class A
> def toto
> puts "tttt"
> end
> end
>
> class B < A
> alias :totoo :toto
> def toto
> puts "mmmm"
> end

def tata
totoo
end

> end
>
> b = B.new
> b.toto
> b.totoo

Ups. :)

Karl-Heinz





Cons@minority#s

4/10/2012 12:54:00 AM

0


"Your Devil Incarnate" <perryneheum@hotmail.com> wrote in message
news:dc4f5c5a-c69f-435c-90ff-e79de895abb1@2g2000yqk.googlegroups.com...
> It's logical.
>
> Blacks play basketball.
>
> Whitey's read and write.
>