is_defined?

E

Eko Budi Setiyo

Any body now how to do some thing like this in ruby

is_class_defined?
is_module_defined?
is_methode_defined?

regards
Eko
 
A

Austin Ziegler

Any body now how to do some thing like this in ruby

is_class_defined?
is_module_defined?
is_methode_defined?

def foo; end
defined?(foo) # => "method"

Both of the following return "constant."

class Foo; end
module Bar; end
defined?(Foo) # => "constant"
defined?(Bar) # => "constant"

-austin
 
N

Navindra Umanee

Austin Ziegler said:
def foo; end
defined?(foo) # => "method"

Both of the following return "constant."

class Foo; end
module Bar; end
defined?(Foo) # => "constant"
defined?(Bar) # => "constant"

Out of curiosity, why doesn't this work:

irb(main):014:0> defined? defined?
SyntaxError: compile error
(irb):14: syntax error
from (irb):14

Cheers,
Navin.
 
A

Austin Ziegler

Out of curiosity, why doesn't this work:

irb(main):014:0> defined? defined?
SyntaxError: compile error
(irb):14: syntax error
from (irb):14

defined? may be a keyword. I don't recall for certain.

-austin
 
E

Eko Budi Setiyo

Austin said:
def foo; end
defined?(foo) # => "method"

Both of the following return "constant."

class Foo; end
module Bar; end
defined?(Foo) # => "constant"
defined?(Bar) # => "constant"

-austin
Thanks
 
M

Minero Aoki

Hi,

In mail "Re: is_defined?"
Navindra Umanee said:
Out of curiosity, why doesn't this work:

irb(main):014:0> defined? defined?
SyntaxError: compile error

Because second defined? does not have argument.

~ % ruby -e 'p defined?(defined?(nil))'
"expression"

Minero Aoki
 
B

Bertram Scharpf

Hi,

Am Montag, 28. Feb 2005, 12:33:35 +0900 schrieb Navindra Umanee:
Out of curiosity, why doesn't this work:

irb(main):014:0> defined? defined?
SyntaxError: compile error
(irb):14: syntax error
from (irb):14

`defined?' is an operator, not a method.

This is confusing as `Module#method_defined?' and
`Module#const_defined?' are methods.

Bertram
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,918
Members
47,458
Latest member
Chris#

Latest Threads

Top