You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
undefined method `extract_ruby_args=' for module IRB::Command (NoMethodError) #958
I ran into the same thing when trying to assign some source code string to a variable named source. I guess this would be because of #824? Not seeing much else in the changelog.
I was curious how python handles this: its repl also has some buildins. The help command for example works, as long as you don't reassign it. exit as well, which means you can only close with ctrl+d, not with exit() anymore. I believe irb should do the same.
In #824, we decided commands should always take precedence over variable names or methods (mostly my idea tbf). This is to avoid situations like having help in the scope of the binding.irb breakpoint unexpectedly disabling the command completely.
But now I think we can do a more sophisticated check to support this precedence order:
Local variables defined in the IRB session
Command name
Local variables or methods in the program context
So in this example:
help=1binding.irb
when users type help in the IRB console, it'd execute the command.
But if users do help = 1, we should allow it, and the subsequent help call would retrieve the local variable instead.
I think it is hard to distinguish local variables defined in program context from local variables defined in IRB session, especially when using chws or rdbg command. And I think the behavior is complex/hard to understand for user.
How about simply make the precedence:
Local variables
Command name
Methods
(This will be a simpler version of #803 (comment))
We still have irb_commandname. When input starts with existing local variable and command name, it is possible to show a navigation message for it.
irb> help=1=>1irb> help + 1Ifyouwanttousehelpcommand,tryirb_helpinstead=>2
And I think the behavior is complex/hard to understand for user.
I personally don't think that'd be the case as they are the ones who define the local variables.
How about simply make the precedence:
Then we'll need to change that for irb:rdbg session together too. Otherwise the behaviour will be inconsistent:
$ ruby test.rb
From: test.rb @ line 3 :
1: help = 1
2:
=> 3: binding.irb
irb(main):001> help
=> 1
irb(main):002> debug
irb:rdbg(main):003> help
### Control flow
* `s[tep]`
* Step in. Resume the program until next breakable point.
* `s[tep] <n>`
* Step in, resume the program at `<n>`th breakable point.
Less inconsistency is better, but I think it will be an enhancement even if there is an inconsistency.
We can change how ruby/debug handles command later.
Just FYI I suspect I'm seeing this bug by following the usage example of the Rouge gem in IRB:
require'rouge'=>truesource=File.read('README.md')
This results in
(eval at /home/me/.rbenv/versions/3.3.5/lib/ruby/3.3.0/irb/command/internal_helpers.rb:22):1:in `<top (required)>': undefined method `extract_ruby_args=' for module IRB::Command (NoMethodError)
IRB::Command.extract_ruby_args = File.read('README.md')
^^^^^^^^^^^^^^^^^^^^
from /home/me/.rbenv/versions/3.3.5/lib/ruby/3.3.0/irb/command/internal_helpers.rb:22:in `eval'
from /home/me/.rbenv/versions/3.3.5/lib/ruby/3.3.0/irb/command/internal_helpers.rb:22:in `block in ruby_args'
from /home/me/.rbenv/versions/3.3.5/lib/ruby/3.3.0/irb/command/internal_helpers.rb:21:in `catch'
from /home/me/.rbenv/versions/3.3.5/lib/ruby/3.3.0/irb/command/internal_helpers.rb:21:in `ruby_args'
from /home/me/.rbenv/versions/3.3.5/lib/ruby/3.3.0/irb/command/load.rb:79:in `execute'
from /home/me/.rbenv/versions/3.3.5/lib/ruby/3.3.0/irb/command/base.rb:42:in `execute'
from /home/me/.rbenv/versions/3.3.5/lib/ruby/3.3.0/irb/context.rb:603:in `evaluate'
from /home/me/.rbenv/versions/3.3.5/lib/ruby/3.3.0/irb.rb:1049:in `block (2 levels) in eval_input'
from /home/me/.rbenv/versions/3.3.5/lib/ruby/3.3.0/irb.rb:1380:in `signal_status'
from /home/me/.rbenv/versions/3.3.5/lib/ruby/3.3.0/irb.rb:1041:in `block in eval_input'
from /home/me/.rbenv/versions/3.3.5/lib/ruby/3.3.0/irb.rb:1120:in `block in each_top_level_statement'
from <internal:kernel>:187:in `loop'
from /home/me/.rbenv/versions/3.3.5/lib/ruby/3.3.0/irb.rb:1117:in `each_top_level_statement'
from /home/me/.rbenv/versions/3.3.5/lib/ruby/3.3.0/irb.rb:1040:in `eval_input'
from /home/me/.rbenv/versions/3.3.5/lib/ruby/3.3.0/irb.rb:1021:in `block in run'
from /home/me/.rbenv/versions/3.3.5/lib/ruby/3.3.0/irb.rb:1020:in `catch'
from /home/me/.rbenv/versions/3.3.5/lib/ruby/3.3.0/irb.rb:1020:in `run'
from /home/me/.rbenv/versions/3.3.5/lib/ruby/3.3.0/irb.rb:904:in `start'
from /home/me/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/irb-1.13.1/exe/irb:9:in `<top (required)>'
from /home/me/.rbenv/versions/3.3.5/bin/irb:25:in `load'
from /home/me/.rbenv/versions/3.3.5/bin/irb:25:in `<main>'
Maybe IRB bug!
Assigning to a var not named "source" fixes the problem.
Activity
rebuilt commentedon May 21, 2024
I assume there's a clash with the irb command
measuremeasureenables the mode to measure processing time.measure :offdisables it.tompng commentedon May 22, 2024
measure = 1is a measure command call withargs = "= 1". Related to #803.The error message is not user friendly so it should be improved.
Earlopain commentedon May 24, 2024
I ran into the same thing when trying to assign some source code string to a variable named
source. I guess this would be because of #824? Not seeing much else in the changelog.I was curious how python handles this: its repl also has some buildins. The
helpcommand for example works, as long as you don't reassign it.exitas well, which means you can only close with ctrl+d, not withexit()anymore. I believe irb should do the same.st0012 commentedon May 25, 2024
In #824, we decided commands should always take precedence over variable names or methods (mostly my idea tbf). This is to avoid situations like having
helpin the scope of thebinding.irbbreakpoint unexpectedly disabling the command completely.But now I think we can do a more sophisticated check to support this precedence order:
So in this example:
when users type
helpin the IRB console, it'd execute the command.But if users do
help = 1, we should allow it, and the subsequenthelpcall would retrieve the local variable instead.WDYT @tompng?
tompng commentedon May 25, 2024
I think it is hard to distinguish local variables defined in program context from local variables defined in IRB session, especially when using chws or rdbg command. And I think the behavior is complex/hard to understand for user.
How about simply make the precedence:
(This will be a simpler version of #803 (comment))
We still have
irb_commandname. When input starts with existing local variable and command name, it is possible to show a navigation message for it.st0012 commentedon May 28, 2024
That's a good point 🤔
I personally don't think that'd be the case as they are the ones who define the local variables.
Then we'll need to change that for
irb:rdbgsession together too. Otherwise the behaviour will be inconsistent:tompng commentedon Jun 29, 2024
Less inconsistency is better, but I think it will be an enhancement even if there is an inconsistency.
We can change how ruby/debug handles command later.
MatzFan commentedon Sep 20, 2024
Just FYI I suspect I'm seeing this bug by following the usage example of the Rouge gem in IRB:
This results in
Assigning to a var not named "source" fixes the problem.