Feature #15915
closed`@1` cannot be achieved in meta-programming
Description
I cannot think of any way to get @1
in meta-programming, so it is hard to inspect it in a debugger.
% ruby -e 'proc{@1;binding.local_variable_get("@1")}.call(1)'
Traceback (most recent call last):
2: from -e:1:in `<main>'
1: from -e:1:in `block in <main>'
-e:1:in `local_variable_get': wrong local variable name `@1' for #<Binding:0x00007f952401e490> (NameError)
Files
Updated by sawa (Tsuyoshi Sawada) over 5 years ago
What is the use case? And how do you want it to be made possible?
Updated by mame (Yusuke Endoh) over 5 years ago
What is the use case?
OP says a debugger. The motivation looks reasonable to me.
And how do you want it to be made possible?
I think it would be technically possible.
If this ticket is accepted, Binding#local_variables
should include numbered parameters. It might be good to allow a symbol like :@1
.
(I'm negative against numbered parameters themselves, though.)
Updated by hanachin (Seiei Miyagi) about 5 years ago
When I debug a proc which use the numbered parameters, I can not inspect the numbered parameters.
Because irb use Binding to evaluate input but the numbered parameters can not get from binding.
square = -> {
binding.irb
@1 * @1
}
square[rand(100)]
% ruby foo.rb
From: foo.rb @ line 2 :
1: square = -> {
=> 2: binding.irb
3: @1 * @1
4: }
5: square[rand(100)]
irb(main):001:0> @1
Traceback (most recent call last):
3: from foo.rb:5:in `<main>'
2: from foo.rb:2:in `block in <main>'
1: from <internal:prelude>:206:in `irb'
SyntaxError ((irb):1: numbered parameter outside block)
I need to give a name to the numbered parameters to inspect value.
It doesn't make sense.
square = -> {
v = @1
binding.irb
@1 * @1
}
square[rand(100)]
Updated by mame (Yusuke Endoh) about 5 years ago
Here is an experimental patch.
Updated by sawa (Tsuyoshi Sawada) about 5 years ago
- Subject changed from `@1` cannot get from meta-programming to `@1` cannot be achieved in meta-programming
- Description updated (diff)
Updated by nobu (Nobuyoshi Nakada) about 5 years ago
I'm negative to add ID_NUMPARAM
.
As rb_is_numparam_id
is not used, and rb_is_numparam_name
can be implemented without rb_symname_type
.
Updated by znz (Kazuhiro NISHIYAMA) almost 5 years ago
- Status changed from Open to Closed
I think this issue resolved by changing from @1
to _1
.
Updated by mame (Yusuke Endoh) over 2 years ago
- Related to Bug #18837: Not possible to evaluate expression with numbered parameters in it added