S
Shak
Hi all,
Why would const-defined? as used below throw a NameError? Surely the whole
point of the method is to tell you what *isn't* defined? Or are we supposed
to look for an exception instead of false? If so, what's the best way of
knowing whether a module contains a certain class or not?
======
module Space
class Time
def hello
puts 'Hello world!'
end
end
end
s = Space::Time.new
s.hello #Hello world!
clazz = Space.const_get('Time') #get class with name
obj = clazz.new #instatiate object
obj.hello #Hello world!
puts Space.const_defined?('Time') # true
puts Space.const_defined?('ime') #throws nameerror
========
Thanks!
Shak
Why would const-defined? as used below throw a NameError? Surely the whole
point of the method is to tell you what *isn't* defined? Or are we supposed
to look for an exception instead of false? If so, what's the best way of
knowing whether a module contains a certain class or not?
======
module Space
class Time
def hello
puts 'Hello world!'
end
end
end
s = Space::Time.new
s.hello #Hello world!
clazz = Space.const_get('Time') #get class with name
obj = clazz.new #instatiate object
obj.hello #Hello world!
puts Space.const_defined?('Time') # true
puts Space.const_defined?('ime') #throws nameerror
========
Thanks!
Shak