diff --git a/.gemspec b/.gemspec deleted file mode 100644 index 5dabb17..0000000 --- a/.gemspec +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env ruby -rubygems -# -*- encoding: utf-8 -*- - -GEMSPEC = Gem::Specification.new do |gem| - gem.version = File.read('VERSION').chomp - gem.date = File.mtime('VERSION').strftime('%Y-%m-%d') - - gem.name = 'quantity' - gem.homepage = 'http://quantity.rubyforge.org/' - gem.license = 'Public Domain' if gem.respond_to?(:license=) - gem.summary = 'Units and quantities for Ruby.' - gem.description = <<-EOF - Quantity provides first-class quantities, units, and base quantities in pure ruby. - Things like 1.meter / 1.second == 1 meter/second. - EOF - gem.rubyforge_project = 'quantity' - - gem.authors = ['Ben Lavender', 'Arto Bendiken'] - gem.email = 'blavender@gmail.com' - - gem.platform = Gem::Platform::RUBY - gem.files = %w(AUTHORS README UNLICENSE VERSION) + Dir.glob('lib/**/*.rb') - gem.bindir = %q(bin) - gem.executables = %w() - gem.default_executable = gem.executables.first - gem.require_paths = %w(lib) - gem.extensions = %w() - gem.test_files = %w() - gem.has_rdoc = false - - gem.required_ruby_version = '>= 1.8.2' - gem.requirements = [] - gem.add_development_dependency 'rspec', '>= 1.2.9' - gem.add_development_dependency 'yard' , '>= 0.5.2' - gem.post_install_message = nil -end diff --git a/Gemfile b/Gemfile index a543bbe..2a3cf4b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source :rubygems +source 'https://rubygems.org' # Specify your gem's dependencies in quantity.gemspec gemspec diff --git a/lib/quantity.rb b/lib/quantity.rb index 2b416da..f76c906 100644 --- a/lib/quantity.rb +++ b/lib/quantity.rb @@ -371,16 +371,3 @@ def respond_to?(method) end end - -# @private -# Plug our constructors into Numeric -class Numeric - alias_method :quantity_method_missing, :method_missing - def method_missing(method, *args, &block) - if Quantity::Unit.is_unit?(method) - Quantity.new(self,Quantity::Unit.for(method)) - else - quantity_method_missing(method,*args, &block) - end - end -end diff --git a/lib/quantity/unit.rb b/lib/quantity/unit.rb index 0f060c6..d7d2555 100644 --- a/lib/quantity/unit.rb +++ b/lib/quantity/unit.rb @@ -42,6 +42,18 @@ def self.is_unit?(to) to.is_a?(Unit) || @@units.has_key?(to) end + # Plug unit constructor into Numeric, to support things like `1.lb` + # @param [Unit, String] + def self.add_numeric_helper(unit, name) + Numeric.class_eval do + unless method_defined?(name) + define_method name do + Quantity.new(self, unit) + end + end + end + end + # Register a unit with the given symbols # @param [Unit] unit # @param [*names] @@ -49,6 +61,7 @@ def self.add_alias(unit,*names) unit = Unit.for(unit) unless unit.is_a? Unit names.each do |name| @@units[name] = unit + add_numeric_helper(unit, name) end end