In ruby, you can find out whether a class is defined by calling:
Object.const_defined?('ClassName')
A simple demonstration of this in an irb session is:
ruby-1.8.7-p330 :020 > Object.const_defined?('String')
=> true
ruby-1.8.7-p330 :021 > Object.const_defined?('Asdf')
=> false
Recently I ran into the problem that some called to Object.const_defined? are raising a NameError instead of returning true or false.
ruby-1.8.7-p330 :022 > Object.const_defined?('asdf')
NameError: wrong constant name asdf
from (irb):22:in `const_defined?'
from (irb):22
I discovered that passing a string that is not capitalized is what causes this problem.
ruby-1.8.7-p330 :023 > Object.const_defined?('asdf'.capitalize)
=> false
This had me scratching my head for a minute. I hope it helps someone out.
