Module: Rupee::FindInstance
- Defined in:
- lib/rupee/mixins/find_instance.rb
Overview
For finding instances within a class
Instance Method Summary collapse
-
#find(x) ⇒ Object
Converts the supplied value to an instance of the specified class (if it isn’t already one).
Instance Method Details
#find(x) ⇒ Object
Converts the supplied value to an instance of the specified class (if it isn’t already one). For example, within the Source object you could find the Bloomberg object one of two ways:
Rupee::Source.find :bloomberg
Rupee::Source.find Rupee::Source::BLOOMBERG
This allows the user more flexibility, as specifying the full path to the BLOOMBERG
constant is no longer necessary
13 14 15 16 17 18 19 20 21 |
# File 'lib/rupee/mixins/find_instance.rb', line 13 def find(x) if x.instance_of?(self) # If x is an actual instance of the class, just return it x else # Otherwise, search for constants after capitalizing x self.const_get x.upcase end end |