Class: SimpleUnits::Context
- Inherits:
-
Object
- Object
- SimpleUnits::Context
- Defined in:
- lib/simple_units/context.rb
Instance Attribute Summary collapse
-
#inspector ⇒ Object
Returns the value of attribute inspector.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name = nil) {|_self| ... } ⇒ Context
constructor
A new instance of Context.
Constructor Details
#initialize(name = nil) {|_self| ... } ⇒ Context
Returns a new instance of Context.
17 18 19 20 |
# File 'lib/simple_units/context.rb', line 17 def initialize(name=nil, &block) @name = name yield(self) end |
Instance Attribute Details
#inspector ⇒ Object
Returns the value of attribute inspector.
16 17 18 |
# File 'lib/simple_units/context.rb', line 16 def inspector @inspector end |
#name ⇒ Object
Returns the value of attribute name.
16 17 18 |
# File 'lib/simple_units/context.rb', line 16 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
16 17 18 |
# File 'lib/simple_units/context.rb', line 16 def type @type end |
Class Method Details
.define_unit(name, &block) ⇒ Object
5 6 7 8 |
# File 'lib/simple_units/context.rb', line 5 def define_unit(name, &block) @contexts ||= {} @contexts[name.to_s] = new(name, &block) end |
.get_context(name) ⇒ Object
10 11 12 13 |
# File 'lib/simple_units/context.rb', line 10 def get_context(name) throw :UndefinedUnitError if @contexts[name].nil? @contexts[name.to_s] end |