Module: Units::UseBlocks
- Included in:
- Units
- Defined in:
- lib/units-system.rb
Overview
This must be included in any module or class from which units expressions are to be used in units or u blocks. It is not needed in Ruby 1.9.1 due to they way constant look-up is done in that version, but Ruby 1.9.2 has changed that an requires this again.
Constant Summary collapse
- @@constants =
an instance variable would not work here because const_missing is executed on other modules (which include this one)
nil
Class Method Summary collapse
Class Method Details
.append_features(target) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/units-system.rb', line 17 def self.append_features(target) def target.const_missing(name) begin name = name.to_sym if name==:Const Units::Const else result = @@constants[name] if @@constants result || Units.Measure(name) end rescue ArgumentError super end end end |
.with_constants(*consts) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/units-system.rb', line 33 def self.with_constants(*consts) prev = @@constants # @@constants = consts.map_hash{|c| Units.constant(c)} @@constants = {} consts.each do |c| c = c.to_sym @@constants[c] = Units.constant(c) end result = yield @@constants = prev result end |