From 2218bf72b07c1ea1d8ee848abab6e391eba183cb Mon Sep 17 00:00:00 2001 From: Kevin Olbrich Date: Sat, 23 Apr 2011 11:29:35 -0400 Subject: [PATCH] update parser to directly perform the conversion to a complex for rubies that don't define it on string (like 1.8) --- lib/ruby_units/unit.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ruby_units/unit.rb b/lib/ruby_units/unit.rb index 1599a1db..ada3e1a6 100644 --- a/lib/ruby_units/unit.rb +++ b/lib/ruby_units/unit.rb @@ -1237,7 +1237,11 @@ def self.parse_into_numbers_and_units(string) when NilClass 1 when complex - num.to_c + if num.respond_to?(:to_c) + num.to_c + else + Complex(*num.scan(/(#{sci})(#{sci})i/).flatten.map {|n| n.to_i}) + end when rational Rational(*num.split("/").map {|x| x.to_i}) else