From: "Wayne E. Seguin" Date: 2007-10-05T23:45:46+09:00 Subject: Re: Refering to an object's 'parent' ------=_Part_10728_30885305.1191595546254 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 10/5/07, Toby Rodwell wrote: > > I'd like to check an object's "parent" to see if it has a certain > method, so for example, given ... > > class House(type) > attr_accessor :rooms, :type_of_house > @rooms = [] > ... > def type_of_house > type > end > end > > class Room > ... > end > > my_room = Room.new > > my_house = House.new > > my_house.rooms.push(my_room) > > ... then is it somehow possible to ask ... > my_room..respond_to?(type_of_house) ? > (I know 'House' is not really the parent of 'Room', and so I suspect the > answer is "no", but it can't hurt to ask. Thanks > I don't believe so the way you have things setup, as there is no relation where my_room knows about my_house since it is simply kept in an array variable inside my_house. If you inherit Room < House then you can do something like this: my_room.class.ancestors[1].respond_to?(type_of_house) But that's at the class level (House) whereas you want the instance (my_house) level. ------=_Part_10728_30885305.1191595546254--