Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions .gemspec

This file was deleted.

2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source :rubygems
source 'https://rubygems.org'

# Specify your gem's dependencies in quantity.gemspec
gemspec
13 changes: 0 additions & 13 deletions lib/quantity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions lib/quantity/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,26 @@ 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]
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

Expand Down