Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Define Quantity#respond_to?

  • Loading branch information...
commit 62794c302f1eb70de5aea5ae22d23342f4fc0a6a 1 parent c6b6d4e
@mtodd mtodd authored
Showing with 16 additions and 1 deletion.
  1. +10 −0 lib/quantity.rb
  2. +6 −1 spec/quantity.spec
View
10 lib/quantity.rb
@@ -360,6 +360,16 @@ def method_missing(method, *args, &block)
end
end
+ def respond_to?(method)
+ if method.to_s =~ /(to_|in_)(.*)/
+ if (Unit.is_unit?($2.to_sym))
+ return true
+ end
+ end
+
+ super
+ end
+
end
# @private
View
7 spec/quantity.spec
@@ -64,7 +64,12 @@ describe Quantity do
it "reduces derived units" do
((1.meter / 1.second) * 1.second).should == 1.meter
end
-
+
+ it "respond_to? conversion methods" do
+ 1.meter.should respond_to(:in_centimeters)
+ 1.meter.should respond_to(:to_centimeters)
+ end
+
end
context "math operations" do
Please sign in to comment.
Something went wrong with that request. Please try again.