mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Merge branch 'master' of git://github.com/evansenter/awesome_print into evansenter/master
This commit is contained in:
commit
c7bdcd85e6
3 changed files with 15 additions and 9 deletions
|
@ -196,12 +196,17 @@ module AwesomePrint
|
|||
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.
|
||||
#------------------------------------------------------------------------------
|
||||
|
|
|
@ -43,6 +43,7 @@ module AwesomePrint
|
|||
:keyword => :cyan,
|
||||
:method => :purpleish,
|
||||
:nilclass => :red,
|
||||
:rational => :blue,
|
||||
:string => :yellowish,
|
||||
:struct => :pale,
|
||||
:symbol => :cyanish,
|
||||
|
|
|
@ -479,14 +479,14 @@ EOS
|
|||
|
||||
#------------------------------------------------------------------------------
|
||||
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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue