Skip to content

Commit 8613403

Browse files
Merge #212 via #253
Handle NoMethodError for IRB implicit #ai Original PR by @jtnegrotto. #253 was only to rebase the work on master.
2 parents 056e5c7 + 15cf3b4 commit 8613403

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## master (unreleased)
2-
2+
- Handles NoMethodError for IRB implicit `ai` [@jtnegrotto] - [#212]
33

44
## 1.7.0
55
- Refactoring by extracting formatters into their own classes [@waldyr] - [#237]
@@ -129,6 +129,7 @@
129129
- Initial Release.
130130

131131
[#200]: https://github.com/awesome-print/awesome_print/pull/200
132+
[#212]: https://github.com/awesome-print/awesome_print/pull/212
132133
[#216]: https://github.com/awesome-print/awesome_print/pull/216
133134
[#217]: https://github.com/awesome-print/awesome_print/pull/217
134135
[#222]: https://github.com/awesome-print/awesome_print/pull/222
@@ -145,6 +146,7 @@
145146
[@clonezone]: https://github.com/clonezone
146147
[@cyberdelia]: https://github.com/cyberdelia
147148
[@gerrywastaken]: https://github.com/gerrywastaken
149+
[@jtnegrotto]: https://github.com/jtnegrotto
148150
[@kemmason]: https://github.com/kemmason
149151
[@maurogeorge]: https://github.com/maurogeorge
150152
[@MaxPleaner]: https://github.com/MaxPleaner

lib/awesome_print/inspector.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def irb!
3131
IRB::Irb.class_eval do
3232
def output_value
3333
ap @context.last_value
34+
rescue NoMethodError
35+
puts "(Object doesn't support #ai)"
3436
end
3537
end
3638
else # MacRuby
@@ -55,7 +57,7 @@ class Inspector
5557
AP = :__awesome_print__
5658

5759
def initialize(options = {})
58-
@options = {
60+
@options = {
5961
:indent => 4, # Indent using 4 spaces.
6062
:index => true, # Display array indices.
6163
:html => false, # Use ANSI color codes rather than HTML.
@@ -65,7 +67,7 @@ def initialize(options = {})
6567
:sort_keys => false, # Do not sort hash keys.
6668
:limit => false, # Limit large output for arrays and hashes. Set to a boolean or integer.
6769
:new_hash_syntax => false, # Use the JSON like syntax { foo: 'bar' }, when the key is a symbol
68-
:color => {
70+
:color => {
6971
:args => :pale,
7072
:array => :white,
7173
:bigdecimal => :blue,
@@ -104,7 +106,7 @@ def current_indentation
104106
def increase_indentation
105107
indentator.indent(&Proc.new)
106108
end
107-
109+
108110
# Dispatcher that detects data nesting and invokes object-aware formatter.
109111
#------------------------------------------------------------------------------
110112
def awesome(object)

spec/misc_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -246,5 +246,17 @@ class IRB; end
246246
expect(capture! { ap({ :a => 1 }) }).to eq(nil)
247247
Object.instance_eval{ remove_const :IRB }
248248
end
249+
250+
it "handles NoMethodError on IRB implicit #ai" do
251+
module IRB; class Irb; end; end
252+
irb_context = double('irb_context', last_value: BasicObject.new)
253+
IRB.define_singleton_method :version, -> { 'test_version' }
254+
irb = IRB::Irb.new
255+
irb.instance_eval { @context = irb_context }
256+
AwesomePrint.irb!
257+
expect(irb).to receive(:puts).with("(Object doesn't support #ai)")
258+
expect { irb.output_value }.to_not raise_error
259+
Object.instance_eval { remove_const :IRB }
260+
end
249261
end
250262
end

0 commit comments

Comments
 (0)