Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binding.irb pollutes the context object's methods #592

Closed
st0012 opened this issue May 30, 2023 · 0 comments · Fixed by #824
Closed

binding.irb pollutes the context object's methods #592

st0012 opened this issue May 30, 2023 · 0 comments · Fixed by #824
Assignees
Labels
bug Something isn't working
Milestone

Comments

@st0012
Copy link
Member

st0012 commented May 30, 2023

Description

Given the code:

class Foo
  def foo
    binding.irb
    puts "Hello"
  end
end

Foo.new.foo

If we run ls from binding.irb, we'd get

Foo.methods: 
  backtrace     bindings  bt                  cb        chws                         conf     context  continue  cws              cwws      debug      delete                     edit                         exit              fg         finish      help      info      
  irb_bindings  irb_cb    irb_change_binding  irb_chws  irb_current_working_binding  irb_cwb  irb_cws  irb_cwws  irb_pop_binding  irb_popb  irb_popws  irb_print_working_binding  irb_print_working_workspace  irb_push_binding  irb_pushb  irb_pushws  irb_pwb   irb_pwws  
  irb_quit      jobs      kill                ls        measure                      popb     popws    pushb     pushws           pwws      quit       show_cmds                  show_doc                     show_source       source     step        whereami  workspaces
IRB::ExtendCommandBundle#methods: 
  install_alias_method  irb       irb_backtrace  irb_break  irb_catch  irb_change_workspace  irb_context  irb_continue       irb_current_working_workspace  irb_debug    irb_debug_info  irb_delete    irb_edit         irb_exit    irb_fg    irb_finish    irb_help      
  irb_info              irb_jobs  irb_kill       irb_load   irb_ls     irb_measure           irb_next     irb_pop_workspace  irb_push_workspace             irb_require  irb_show_cmds   irb_show_doc  irb_show_source  irb_source  irb_step  irb_whereami  irb_workspaces
Foo#methods: foo
locals: _
=> nil

This shows that IRB's command methods got added to the object, which is a pretty bad side-effect. This is because IRB directly calls extend(ExtendCommandBundle) on the context.main here.

I think we should stop treating commands as methods to properly solve this, which will also make command extension API easier to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

1 participant