Allow inspecting implicit parameters via `implicit_parameter_get` etc.

Open
#1,210 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
ruby
Domain
cli, devtools

Research direction

Start by reading Ruby 4.0's implicit-parameter interrogation methods referenced in the linked Ruby issue and the binding.irb behavior shown in the example. Trace how IRB evaluates names such as it and _1, then verify that implicit_parameter_get and related methods can inspect them from the session without rewriting the block.

Written by the indexing model from the issue text.

Description

Currently, it is not possible to know what implicit parameters like it/_1 actually are. If I want to know, I have to rewrite the block to take explicit parameters.

[1, 2, 3].each do
  puts it
  binding.irb
end
$ ruby test.rb
1

From: test.rb @ line 3 :

    1: [1, 2, 3].each do
    2:   puts it
 => 3:   binding.irb
    4: end

irb(main):001> it
/home/user/code/test/test.rb(irb):1:in 'block in <main>': undefined local variable or method 'it' for main (NameError)
        from test.rb:3:in 'Binding#irb'
        from test.rb:3:in 'block in <main>'
        from test.rb:1:in 'Array#each'
        from test.rb:1:in '<main>'

Ruby 4.0 actually added methods to interogate the values of such params (https://bugs.ruby-lang.org/issues/21049#note-7) and it would be great if it can just work in irb.

Dominant language
Ruby
Stars
477
Forks
165
Avg merge
1d 19h
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ruby/irb

All issues in ruby/irb

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.