Module: Units::Const

Defined in:
lib/units/system.rb

Class Method Summary collapse

Class Method Details

.define(name, description, value) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/units/system.rb', line 238

def self.define(name, description, value)
  symbol = name.to_sym
  cd = ConstantDefinition.new(symbol, description, value)
  CONSTANTS[symbol] = cd
  class_eval do
    # Ruby 1.9.1 allows this nicer definition:
    #   define_singleton_method name do
    #     value
    #   end
    eigenclass = class<<self; self; end
    eigenclass.instance_eval{define_method(name){value}}
  end
end