From f36e788584801aa528a284693b54faeee4467a6d Mon Sep 17 00:00:00 2001 From: Michael Dvorkin Date: Tue, 5 Nov 2013 10:58:45 -0800 Subject: [PATCH] Fixed incompatibility with the money gem v5 --- lib/awesome_print/formatter.rb | 4 ++-- spec/misc_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/awesome_print/formatter.rb b/lib/awesome_print/formatter.rb index 6364e89..329b0e6 100755 --- a/lib/awesome_print/formatter.rb +++ b/lib/awesome_print/formatter.rb @@ -63,8 +63,8 @@ module AwesomePrint def awesome_self(object, type) if @options[:raw] && object.instance_variables.any? awesome_object(object) - elsif object.eql?(ENV) # See https://github.com/michaeldv/awesome_print/issues/134 - awesome_hash(ENV.to_hash) + elsif object.respond_to?(:to_hash) + awesome_hash(object.to_hash) else colorize(object.inspect.to_s, type) end diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb index d359ca6..54a61fc 100644 --- a/spec/misc_spec.rb +++ b/spec/misc_spec.rb @@ -64,6 +64,18 @@ describe "AwesomePrint" do ipaddr = IPAddr.new("3ffe:505:2::1") ipaddr.ai.should == "#" end + + # See https://github.com/michaeldv/awesome_print/issues/139 + it "Object that overrides == and expects the :id method" do + weird = Class.new do + # Raises NoMethodError: undefined method `id' when "other" is nil or ENV. + def ==(other) + self.id == other.id + end + alias :eql? :== + end + lambda { weird.new.ai }.should_not raise_error + end end #------------------------------------------------------------------------------