Module: EagleClaw::ConstantMatcher
- Included in:
- Formatters, Scrapers
- Defined in:
- lib/eagleclaw/constmatch.rb
Overview
Mixin to allow an object to act as a case-insensitive hash against its own constants. This should be used with singleton metaclasses, like so:
class MyClass
class << self
include EagleClaw::ConstantMatcher
end
end
Instance Method Summary collapse
-
#[](constant) ⇒ Object
Retrieve the constant for the given symbol.
Instance Method Details
#[](constant) ⇒ Object
Retrieve the constant for the given symbol. Matching will be performed case-insensitively.
23 24 25 26 27 28 |
# File 'lib/eagleclaw/constmatch.rb', line 23 def [](constant) constants.each do |const| return const_get(const) if const.to_s.downcase == constant.to_s.downcase end raise NameError, "Constant #{constant.inspect} not found" end |