From b35bedbbd3c0eab737f6ca77022f5494f5c09e86 Mon Sep 17 00:00:00 2001 From: Kevin McCormack Date: Tue, 5 Oct 2021 09:00:14 -0400 Subject: [PATCH 1/2] Update Irb integration for v1.2.6+ I noticed when using amazing print on recent version of IRB that I would get an invalid number of arguments error. I then found this commit that added an argument to #output_value so this adds the optional argument. https://github.com/ruby/irb/commit/c5ea79d5cecea9cae6ad0c1f31703a98cd329431 --- lib/amazing_print/custom_defaults.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/amazing_print/custom_defaults.rb b/lib/amazing_print/custom_defaults.rb index 44ad4a8..f2ce687 100644 --- a/lib/amazing_print/custom_defaults.rb +++ b/lib/amazing_print/custom_defaults.rb @@ -29,7 +29,7 @@ def inspect_object(object) def usual_rb IRB::Irb.class_eval do - def output_value + def output_value(omit = false) ap @context.last_value rescue NoMethodError puts "(Object doesn't support #ai)" From 3bc26d6caf370738c09e3d6693d5cc658ce735b7 Mon Sep 17 00:00:00 2001 From: Kevin McCormack Date: Tue, 5 Oct 2021 16:00:39 -0400 Subject: [PATCH 2/2] Rubocop fixes --- lib/amazing_print/custom_defaults.rb | 2 +- lib/amazing_print/formatters/base_formatter.rb | 6 +++--- spec/methods_spec.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/amazing_print/custom_defaults.rb b/lib/amazing_print/custom_defaults.rb index f2ce687..add5bd2 100644 --- a/lib/amazing_print/custom_defaults.rb +++ b/lib/amazing_print/custom_defaults.rb @@ -29,7 +29,7 @@ def inspect_object(object) def usual_rb IRB::Irb.class_eval do - def output_value(omit = false) + def output_value(_omit = false) # rubocop:disable Style/OptionalBooleanParameter ap @context.last_value rescue NoMethodError puts "(Object doesn't support #ai)" diff --git a/lib/amazing_print/formatters/base_formatter.rb b/lib/amazing_print/formatters/base_formatter.rb index db53a40..8ba0f53 100644 --- a/lib/amazing_print/formatters/base_formatter.rb +++ b/lib/amazing_print/formatters/base_formatter.rb @@ -49,7 +49,7 @@ def limited(data, width, is_hash: false) else # Calculate how many elements to be displayed above and below the separator. head = limit / 2 - tail = head - (limit - 1) % 2 + tail = head - ((limit - 1) % 2) # Add the proper elements to the temp array and format the separator. temp = data[0, head] + [nil] + data[-tail, tail] @@ -118,13 +118,13 @@ def indented(&blk) INDENT_CACHE = (0..100).map { |i| ' ' * i }.map(&:freeze).freeze def indent(n = indentation) - INDENT_CACHE[n] || ' ' * n + INDENT_CACHE[n] || (' ' * n) end def outdent i = indentation - options[:indent].abs - INDENT_CACHE[i] || ' ' * i + INDENT_CACHE[i] || (' ' * i) end def align(value, width) diff --git a/spec/methods_spec.rb b/spec/methods_spec.rb index 87d464a..995e08e 100644 --- a/spec/methods_spec.rb +++ b/spec/methods_spec.rb @@ -440,7 +440,7 @@ def self.m2; end class World def self.m1; end end - out = (Hello.methods & World.methods - Class.methods).ai(plain: true) + out = (Hello.methods & (World.methods - Class.methods)).ai(plain: true) expect(out).to eq("[\n [0] m1() Hello\n]") end