From: MonkeeSage Date: 2007-12-07T22:49:59+09:00 Subject: Re: function like "function_exits" On Dec 7, 7:31 am, Girard Fred wrote: > Jordan Callicoat wrote: > > On Dec 7, 5:33 am, Alex Young wrote: > >> >> A method and a function are the same thing. Also, check this out. > > >> Alex > > Toplevel methods are implicitly added as private methods of class > > Object, so... > > > p self.private_methods.include?("foo") # => true > > > Regards, > > Jordan > > It's true, i try this differents ways : > in irb:>> def foo > >> puts 'test' > >> end > => nil > >> methods.include? "foo > > => true > -------------------- > in test file: > def foo() > puts 'test' > end > > puts methods.include?('foo') > > => false > --------------------- > So, now with your private_methods > > def foo() > puts 'test' > end > > puts private_methods.include?('foo') > > => true > > Good job :) > -- > Posted viahttp://www.ruby-forum.com/. But you don't really want that... ;) You want respond_to? which Just Works everywhere. And really, you probably don't even want to be asking if a method is defined (depends on your code), but usually there are better ways of doing things (like unit testing). HTH, Jordan