diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a06a6b5..dd10f7a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -20,6 +20,8 @@ updates: patterns: - '*rubocop*' - package-ecosystem: 'bundler' + # For feature dependedncy updates, + # Keep this definition even if the /gemfiles/oldest/Gemfile is completely same as /Gemfile directory: '/gemfiles/oldest' schedule: interval: 'weekly' diff --git a/README.md b/README.md index 60c39b7..96b9aae 100644 --- a/README.md +++ b/README.md @@ -46,28 +46,6 @@ $ irb Then you can use `pa` as an IRB command. -```ruby -irb(main):001:0> pa %q{ "0".class == "3".to_i.times.map {|i| i + 1 }.class } -result: false - - "0".class == "3".to_i.times.map {|i| i + 1 }.class - | | | | | | - | | | | | Array - | | | | [1, 2, 3] - | | | # - | | 3 - | false - String -=> nil -``` - -The `pa` just takes strings of the code. - -If you want to directly pass `expression`, [.irbrc](examples/.irbrc) is the hack for single line code.\ -if you don't have the file yet, putting the file as one of your `$IRBRC`, `$XDG_CONFIG_HOME/irb/irbrc` or `$HOME/.irbrc` - -Then you can use the `pa` as below... - ```ruby irb(main):001:0> pa "0".class == "3".to_i.times.map {|i| i + 1 }.class result: false @@ -83,8 +61,11 @@ result: false => nil ``` +No hack is needed in your irbrc, thank you irb developers! + ## References - [power-assert-js/power-assert](https://github.com/power-assert-js/power-assert) - [Power Assert in Ruby](https://speakerdeck.com/k_tsj/power-assert-in-ruby) - [ja - IRB is new than Pry](https://k0kubun.hatenablog.com/entry/2021/04/02/211455) +- [Support command registration](https://github.com/ruby/irb/pull/886) diff --git a/examples/.irbrc b/examples/.irbrc deleted file mode 100644 index 8158c7d..0000000 --- a/examples/.irbrc +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -require 'irb/power_assert' - -# This logic taken from following reference, @k0kubun thank you! -# * https://github.com/k0kubun/dotfiles/blob/8762ee623adae0fba20ed0a5ef7c8ff5825dc20a/config/.irbrc#L241-L262 -# * https://k0kubun.hatenablog.com/entry/2021/04/02/211455 -IRB::Context.prepend(Module.new{ - kwargs = Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0') ? ', **' : '' - line = __LINE__; eval %q{ - def evaluate(line, *__ARGS__) - case line - when /\Apa / - line.replace("pa #{line.sub(/\Apa +/, '').strip.dump}\n") - end - super - end - }.sub(/__ARGS__/, kwargs), nil, __FILE__, line -}) diff --git a/gemfiles/oldest/Gemfile b/gemfiles/oldest/Gemfile index a78d1cb..4abd2e9 100644 --- a/gemfiles/oldest/Gemfile +++ b/gemfiles/oldest/Gemfile @@ -15,6 +15,6 @@ group :test do gem 'test-unit', '~> 3.6.2' gem 'warning', '~> 1.3.0' - gem 'irb', '1.12.0' + gem 'irb', '1.13.0' gem 'power_assert', '2.0.3' end diff --git a/irb-power_assert.gemspec b/irb-power_assert.gemspec index 12db26b..ddc37f2 100644 --- a/irb-power_assert.gemspec +++ b/irb-power_assert.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |gem| 'rubygems_mfa_required' => 'true', } - gem.add_runtime_dependency 'irb', '>= 1.12.0', '< 2.0' + gem.add_runtime_dependency 'irb', '>= 1.13.0', '< 2.0' gem.add_runtime_dependency 'power_assert', '>= 2.0.3', '< 3.0' gem.required_ruby_version = '>= 3.2' diff --git a/lib/irb/cmd/pa.rb b/lib/irb/cmd/pa.rb index a383914..6615484 100644 --- a/lib/irb/cmd/pa.rb +++ b/lib/irb/cmd/pa.rb @@ -19,13 +19,5 @@ def execute(expression) end end - if ::IRB::Command.respond_to?(:register) - Command.register(:pa, PaCommand) - else - Command::Pa = PaCommand - - module ExtendCommandBundle - def_extend_command(:irb_pa, :Pa, __FILE__, [:pa, NO_OVERRIDE]) - end - end + Command.register(:pa, PaCommand) end diff --git a/test/test_irb_power_assert.rb b/test/test_irb_power_assert.rb index baa21c9..2a5a0d6 100644 --- a/test/test_irb_power_assert.rb +++ b/test/test_irb_power_assert.rb @@ -35,23 +35,10 @@ def test_typical_example EOD out, err = capture_output do - if ::IRB::Command.respond_to?(:register) - # Since ruby 3.4 (or newer irb gem), no need irbrc hack to realize `pa exp` instead of `pa 'exp'` - execute_lines(%q{pa "0".class == "3".to_i.times.map {|i| i + 1 }.class}) - else - IRB.setup(__FILE__, argv: []) - IRB.conf[:USE_MULTILINE] = true - IRB.conf[:USE_SINGLELINE] = false - IRB.conf[:VERBOSE] = false - workspace = IRB::WorkSpace.new(self) - irb = IRB::Irb.new(workspace) - IRB.conf[:MAIN_CONTEXT] = irb.context - - irb.context.main.irb_pa(%q{"0".class == "3".to_i.times.map {|i| i + 1 }.class}) - end + execute_lines(%q{pa "0".class == "3".to_i.times.map {|i| i + 1 }.class}) end assert_equal('', err) - assert_equal((::IRB::Command.respond_to?(:register) ? expected + "=> nil\n" : expected), out) + assert_equal(expected + "=> nil\n", out) end end