Sha256: aa400878b83d5d738fdfa4dc71afc520bd7a29bd00f01eb2c8e4c9acea744e2f
Contents?: true
Size: 1013 Bytes
Versions: 5
Compression:
Stored size: 1013 Bytes
Contents
module Quantify def self.configure &block self.module_eval &block if block end module ExtendedMethods # Provides syntactic sugar for accessing units via the #for method. # Specify: # # Unit.degree_celsius # # rather than Unit.for :degree_celsius # def method_missing(method, *args, &block) if method.to_s =~ /((si|non_si|compound)_)?(non_(prefixed)_)?((base|derived|benchmark)_)?units(_by_(name|symbol|label))?/ if $2 or $4 or $6 conditions = [] conditions << "unit.is_#{$2}_unit?" if $2 conditions << "!unit.is_prefixed_unit?" if $4 conditions << "unit.is_#{$6}_unit?" if $6 units = Unit.units.select { |unit| instance_eval(conditions.join(" and ")) } else units = Unit.units end return_format = ( $8 ? $8.to_sym : nil ) units.map(&return_format) elsif unit = Unit.for(method) return unit else super end end end end
Version data entries
5 entries across 5 versions & 1 rubygems