Class: SimpleUnits::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_units/context.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) {|_self| ... } ⇒ Context

Returns a new instance of Context.

Yields:

  • (_self)

Yield Parameters:



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

#inspectorObject

Returns the value of attribute inspector.



16
17
18
# File 'lib/simple_units/context.rb', line 16

def inspector
  @inspector
end

#nameObject

Returns the value of attribute name.



16
17
18
# File 'lib/simple_units/context.rb', line 16

def name
  @name
end

#typeObject

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