Skip to content
Browse files

Merge branch 'master' of git://github.com/evansenter/awesome_print in…

…to evansenter/master
  • Loading branch information...
2 parents 39bf45e + bd032ca commit c7bdcd85e6c07b0102173975d76a536c8ab96d4a @michaeldv committed
Showing with 15 additions and 9 deletions.
  1. +8 −3 lib/awesome_print/formatter.rb
  2. +1 −0 lib/awesome_print/inspector.rb
  3. +6 −6 spec/formats_spec.rb
View
11 lib/awesome_print/formatter.rb
@@ -196,12 +196,17 @@ def awesome_dir(d)
colorize(ls.empty? ? d.inspect : "#{d.inspect}\n#{ls.chop}", :dir)
end
- # Format BigDecimal and Rational objects by convering them to Float.
+ # Format BigDecimal object.
#------------------------------------------------------------------------------
def awesome_bigdecimal(n)
- colorize(n.to_f.inspect, :bigdecimal)
+ colorize(n.to_s("F"), :bigdecimal)
+ end
+
+ # Format Rational object.
+ #------------------------------------------------------------------------------
+ def awesome_rational(n)
+ colorize(n.to_s, :rational)
end
- alias :awesome_rational :awesome_bigdecimal
# Format a method.
#------------------------------------------------------------------------------
View
1 lib/awesome_print/inspector.rb
@@ -43,6 +43,7 @@ def initialize(options = {})
:keyword => :cyan,
:method => :purpleish,
:nilclass => :red,
+ :rational => :blue,
:string => :yellowish,
:struct => :pale,
:symbol => :cyanish,
View
12 spec/formats_spec.rb
@@ -479,14 +479,14 @@
#------------------------------------------------------------------------------
describe "BigDecimal and Rational" do
- it "should present BigDecimal object as Float scalar" do
- big = BigDecimal("2010.4")
- big.ai(:plain => true).should == "2010.4"
+ it "should present BigDecimal object with arbitrary precision" do
+ big = BigDecimal("201020102010201020102010201020102010.4")
+ big.ai(:plain => true).should == "201020102010201020102010201020102010.4"
end
- it "should present Rational object as Float scalar" do
- rat = Rational(2010, 2)
- rat.ai(:plain => true).should == "1005.0"
+ it "should present Rational object with arbitrary precision" do
+ rat = Rational(201020102010201020102010201020102010, 2)
+ rat.ai(:plain => true).should == "100510051005100510051005100510051005/1"
end
end

0 comments on commit c7bdcd8

Please sign in to comment.
Something went wrong with that request. Please try again.