Repository navigation
Proposal - show_source-ish command #526
Copy link
Copy link
Closed as not planned
Labels
enhancementNew feature or requestNew feature or request
Description
Naming Options
show-source- I prefer this because:
- I used to use
prya lot so I'm used to it. - Basically impossible to conflict with user's variable/method name.
- I used to use
- I prefer this because:
show_source- something else
- If we go for this option, a one-word name would probably be better.
- But to get people onboard more easily, I think an alias to
show-sourceorshow_sourcemay still be needed.
Interface
show-source- same asshow-source selfshow-source obj- show the object's classshow-source obj.method- show the method's definitionshow-source class- show class definitionshow-source class#method- show the method's definitionshow-source class.method- show the method's definition
Output Format
pry
[2] pry(main)> show-source Bar#foo
From: foo.rb:6:
Owner: Bar
Visibility: public
Signature: foo()
Number of lines: 3
def foo
super
end
irb
irb(main):001:0> show_source "Bar#foo"
From: foo.rb:6
def foo
super
end
=> nil
You can see that pry provides a nicer output. But we can probably start from something simpler, like irb's.
Support for super
pry's show-source also supports using -s option to access the method's super definition.
class Foo
def foo; end
end
class Bar < Foo
def foo
super
end
end[2] pry(main)> show-source Bar#foo
Owner: Bar
Visibility: public
Signature: foo()
Number of lines: 3
def foo
super
end
[3] pry(main)> show-source Bar#foo -[]()s
From: foo.rb:2:
Owner: Foo
Visibility: public
Signature: foo()
Number of lines: 1
def foo; end
You can even use multiple s to access farther definitions. And it'd print a warning when there's no more superclasses.
[4] pry(main)> show-source Bar#foo -ss
Error: No superclass found for #<UnboundMethod: Bar#foo() foo.rb:6>
(I think irb's show_source currently doesn't support this feature.)
I believe this is something we should support from the beginning. But currently the debugger dosn't take command options like -opt and I don't think we'll support that in the near future. So we need to come up with another way to do it.
Perhaps show-source Bar#foo level:[num] ?
show-source Bar#foo level:0- showsBar#fooshow-source Bar#foo level:1- showsFoo#foo
Looking for Feedback
- Name?
- Is there any options from either
pryorirb'sshow*sourcecommand should also be considered? - Anything to add/remove from the output?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Activity
palkan commentedon Feb 15, 2022
I like
show-source; what about a shortcut? Like$.For
super, it would be useful to see a parent of the method:That could eliminate the need of
-s, probably (never used it with Pry).ko1 commentedon Feb 21, 2022
I don't want to introduce
foo-barstyle naming for consistency.list obj#methodfor example?st0012 commentedon Feb 22, 2022
Yeah it's good to have parent info. But there could be multiple levels of super, so I think something like
level:is still needed.I think it's great 👍
What about the
superoption? Do you acceptlist Foo#bar level:2orlist Foo#bar s:2?ko1 commentedon Mar 20, 2022
list Foo#barhas pros/cons.pros.
show[-_]sourceand so oncons.
listcommand? continue to show theFoo#bar?The difficulties can be solved with
pagerconfiguration likepry(and git command for example).ko1 commentedon Mar 20, 2022
Note that
prydoesn't use pager for$ foo#bar, but use it on printing the value.ko1 commentedon Mar 20, 2022
pry's
show-sourceonly prints the definition of method, but maybelist Foo#barshows the source code lines beginning fromFoo#bar(with other method lines).Do you want to see completely same with pry?
(and with headers?)
st0012 commentedon Mar 21, 2022
If you can accept alias like
show_source, it's essentially having a new command to users. In that case, I think adding that functionality tolistcommand makes things unnecessarily complicated.So to me, the options are:
listcommand, with no alias.listas it is.I prefer having a
show[-_]sourcecommand and replicate whatpryhas. This will save us the effort to redefinelist's behavior.zenspider commentedon Jul 8, 2022
Other things pry's cmd can do:
$ ModuleOrClassand it shows the whole thing. There's also-afor "all" which I think would do so even if you say#method$ obj.m1.m2.m3evaluatesobj.m1.m2and shows the appropriate source for m3 based on receiverPerhaps differently... but there's also
whereamiand it takes--method,--class, and--fileargs to show the source around the current frame at multiple levels.ko1 commentedon Sep 16, 2022
does pry has
show-XXXother thansource?ko1 commentedon Sep 16, 2022
Does not support open classes?
I'm not sure we can support it...
sambostock commentedon Oct 20, 2022
The two features I use the most from Pry are
show-source(via the alias$), andls(sometimes with--grep). As someone who installspryon most of my projects, adding support forshow-source(preferably including the alias) todebugwould make it really compelling to switch over.As far as supporting open classes, from trying out some scenarios in Pry, it seems to take a "best guess" approach when it comes to surfacing places a class is re-opened, but it is certainly not perfect. However, I think this is acceptable behavior.
miharekar commentedon Mar 26, 2024
2 years on, and still the only thing I miss daily from the
prydays 😅Were there any more discussions somewhere?
st0012 commentedon Apr 4, 2024
Not exactly the same, but with the latest
debugand IRB, you can useRUBY_DEBUG_IRB_CONSOLE=1env var to make IRB thedebug's default console. And then you can use IRB'sshow_source(and other commands) in addition to the debug's commands in your debugging sessions.nightpool commentedon Aug 27, 2025
What's the long-term plan for this? Is IRB going to be the default console for debug eventually, or is debug going to implement their own show_source command?