Re: function like "function_exits"
- From: MonkeeSage <MonkeeSage@xxxxxxxxx>
- Date: Fri, 7 Dec 2007 07:35:16 -0800 (PST)
On Dec 7, 8:40 am, Robert Dober <robert.do...@xxxxxxxxx> wrote:
On Dec 7, 2007 2:49 PM, MonkeeSage <MonkeeS...@xxxxxxxxx> wrote:
On Dec 7, 7:31 am, Girard Fred <fred.gir...@xxxxxxxxx> wrote:
Jordan Callicoat wrote:
On Dec 7, 5:33 am, Alex Young <a...@xxxxxxxxxxxxxxx> wrote:
A method and a function are the same thing. Also, check this out.
AlexToplevel 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
=> nilputs 'test'
end
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.
No, it behaves the same, you will get a respond_to?(foo) false at the
main level.
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
--
http://ruby-smalltalk.blogspot.com/
---
All truth passes through three stages. First, it is ridiculed. Second,
it is violently opposed. Third, it is accepted as being self-evident.
Schopenhauer (attr.)
You have to pass a second parameter to respond_to? to include private
methods. ;)
Regards,
Jordan
.
- References:
- function like "function_exits"
- From: Girard Fred
- Re: function like "function_exits"
- From: Robert Dober
- Re: function like "function_exits"
- From: Girard Fred
- Re: function like "function_exits"
- From: Peter Bunyan
- Re: function like "function_exits"
- From: Robert Dober
- Re: function like "function_exits"
- From: Alex Young
- Re: function like "function_exits"
- From: MonkeeSage
- Re: function like "function_exits"
- From: Girard Fred
- Re: function like "function_exits"
- From: MonkeeSage
- Re: function like "function_exits"
- From: Robert Dober
- function like "function_exits"
- Prev by Date: Re: Random users generator
- Next by Date: Re: Worth an RCR? static_type_check, polymorphic_type_check,
- Previous by thread: Re: function like "function_exits"
- Next by thread: regular expression. newbie problem.
- Index(es):
Relevant Pages
|