Class: Unit::BaseUnit
- Inherits:
-
Object
- Object
- Unit::BaseUnit
- Defined in:
- lib/unitmanager/simple_unit.rb
Direct Known Subclasses
Class Method Summary collapse
-
.once(*methods) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#[](symbol) ⇒ Object
This method allows to retrieve symbolic portions of the unit definition.
Class Method Details
.once(*methods) ⇒ Object
:nodoc:
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/unitmanager/simple_unit.rb', line 26 def once (*methods) #:nodoc: methods.each {|method| module_eval <<-"end;" alias_method :__#{method.to_i}__ , :#{method.to_s} def #{method.to_s}(*args, &block) if defined? @__#{method.to_i}__ @__#{method.to_i}__ else @__#{method.to_i}__ ||= __#{method.to_i}__(*args, &block) end end private :__#{method.to_i}__ end; } end |
Instance Method Details
#[](symbol) ⇒ Object
This method allows to retrieve symbolic portions of the unit definition. Supported values are: :dividends - returns an array of symbols representing dividend part of
unit definition.
:divisors - returns an array of symbols representing divisor part of
unit definition.
:string - string representation of the unit of measure.
56 57 58 |
# File 'lib/unitmanager/simple_unit.rb', line 56 def [] (symbol) unit_sym[symbol] end |