On Dec 7, 5:33 am, Alex Young <a... / blackkettle.org> wrote: > Robert Dober wrote: > > On Dec 7, 2007 8:35 AM, Peter Bunyan <peter.bun... / gmail.com> wrote: > >>> Thanks for your answer Robert. > >>> It's not a method but a simple function like > >>> def foo() > >>> #some code > >>> end > > >>> is there something like : > >>> functions.exist?('foo') > >> A method and a function are the same thing. Also, check this out. > > >> def foo > >> puts "Foo is being called." > >> end > > >> methods.include? "foo" > >> => true > > you surely mean false here, right? > > the methods method of the toplevel does not seem to include the user > > defined methods, or is this just a bug? > > They're included in IRB: > > irb(main):001:0> def foo > irb(main):002:1> puts "Foo is being called" > irb(main):003:1> end > => nil > irb(main):004:0> methods.include? "foo" > => true > > but not in a script: > > alex@shaxam:~$ cat toplevel.rb > def foo > puts "Foo is being called" > end > p methods.include?("foo") > > alex@shaxam:~$ ruby toplevel.rb > false > > -- > Alex Toplevel methods are implicitly added as private methods of class Object, so... p self.private_methods.include?("foo") # => true Regards, Jordan