`show_source` can't find some sources defined in the session
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- Ruby
- Stars
- 478
- Forks
- 158
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 12
Description
Description
irb can find the source of a method defined during the repl session, but not its parent class.
irb(main):001* class Foo
irb(main):002* def x = "Hello, world!"
irb(main):003> end
=> :x
irb(main):004> Foo.instance_method(:x).source_location
=> ["(irb)", 2]
irb(main):005> show_source Foo#x # Works ✅
From: (irb):2
def x = "Hello, world!"
=> nil
irb(main):006> show_source Foo # Not found ❌
Error: Couldn't locate a definition for Foo
=> nil
A similar thing happens if you execute a script from standard input
$ ruby
class Foo
def x = "Hello, world!"
end
binding.irb
< I press ctrl-d to send EOF >
irb(main):001> Foo.instance_method(:x).source_location
=> ["-", 2]
irb(main):002> show_source Foo#x # Not found ❌
Error: Couldn't locate a definition for Foo#x # Not found ❌
=> nil
irb(main):003> show_source Foo # Not found ❌
Error: Couldn't locate a definition for Foo # Not found ❌
=> nil
Notes
This does work if running from a saved script:
# example_script.rb
class Foo
def x = "Hello, world!"
end
binding.irb
ruby ./example_script.rb
From: ./example_script.rb @ line 5 :
1: class Foo
2: def x = "Hello, world!"
3: end
4:
=> 5: binding.irb
irb(main):001> show_source Foo
From: ./example_script.rb:1
class Foo
def x = "Hello, world!"
end
nil
Result of irb_info
irb(main):001> irb_info
Ruby version: 3.3.0
IRB version: irb 1.13.1 (2024-05-05)
InputMethod: RelineInputMethod with Reline 0.5.8
Completion: Autocomplete, RegexpCompletor
RUBY_PLATFORM: x86_64-linux
LANG env: en_US.UTF-8
LC_ALL env: en_US.UTF-8
East Asian Ambiguous Width: 1
## Terminal Emulator
What's your terminal emulator? **iTerm 2.**
## Setting Files
Are you using `~/.irbrc` and `~/.inputrc`? **Nope.**
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the show_source command and compare how it resolves methods and parent classes defined in an IRB session, from standard input, and from a saved script. Reproduce the examples in the issue and make the command locate the session-defined class and method sources consistently without regressing saved-script behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100