From: Rick DeNatale Date: 2007-06-02T21:05:26+09:00 Subject: Re: nested methods don't really exist?! On 6/2/07, Trans wrote: > > > On Jun 1, 6:57 pm, "Rick DeNatale" wrote: > > Now if one wanted to avoid re-defining such inner methods, one could > > write something like: > > > > class A > > def outer > > unless self.class.instance_methods(false).include?(:inner) > > def inner > > "inner: a regular instance method" > > end > > end > > unless singleton_methods(false).include?(:my_inner) > > def self.my_inner > > "my_inner: a singleton instance method" > > end > > end > > end > > end > > Could. Though the would not work if the method were defined in an > included module. It was a conscious choice on my part to using instance_methods(false) for the instance method. This allows overriding with a new method, but not redefining it the second time. If you wanted to not override then you could use just instance_methods with the default true parameter which returns methods from superclasses and included modules also. It's a matter of what you are trying to do. There are other techniques for determining the current state, like using defined?, with different variations and edge cases. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/