Project

General

Profile

Actions

Bug #18837

closed

Not possible to evaluate expression with numbered parameters in it

Added by hurricup (Alexandr Evstigneev) over 2 years ago. Updated over 2 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:108983]

Description

I presume it's not really a bug, but design flaw, but this is really frustrating. Use case is - debugger.

Here is script with expected behavior:

def dumper(bnd)
  puts bnd.local_variable_get 'i'
  puts bnd.eval 'i * 10'
end

[1,2].each { |i| dumper(binding) }

And this one attempts to do the same with numbered params:

def dumper(bnd)
  puts bnd.local_variable_get('_1')
  puts bnd.eval '_1 * 10'
end

[1,2].each do
  some = _1  # without this line even local_variable_get won't work, still it may be in any place of block
  dumper(binding)
end

But eval wont ever work and this necessity for using _1 so binding could see it may be confusing as well.


Related issues 3 (1 open2 closed)

Related to Ruby master - Feature #15915: `@1` cannot be achieved in meta-programmingClosedActions
Related to Ruby master - Feature #19137: Numbered parameters are not made available to IRB.OpenActions
Has duplicate Ruby master - Bug #20308: `it` and numbered parameters do not work in `eval`ClosedActions
Actions #1

Updated by mame (Yusuke Endoh) over 2 years ago

  • Related to Feature #15915: `@1` cannot be achieved in meta-programming added

Updated by mame (Yusuke Endoh) over 2 years ago

I talked a bit with some of the committers.

@ko1 (Koichi Sasada) said that it is difficult to retrieve _1 afterwards due to the current implementation limitation, since the actual arguments may be dropped by optimization when a block that does not accept formal arguments is called.

Also, @znz (Kazuhiro NISHIYAMA) pointed out that the meta-programming API to read out only _1 is somewhat unreasonable, since the meaning of _1 depends on the presence of _2.

{ 1 => "A" }.each do
  p _1 #=> [1, "A"]
end

{ 1 => "A" }.each do
  p _1 #=> 1
  _2
end

Updated by mame (Yusuke Endoh) over 2 years ago

  • Status changed from Open to Rejected

We discussed this issue at the dev meeting. @matz (Yukihiro Matsumoto) agreed that it is difficult to support this for the reasons I said in #note-2.

Actions #4

Updated by alanwu (Alan Wu) almost 2 years ago

  • Related to Feature #19137: Numbered parameters are not made available to IRB. added
Actions #5

Updated by nobu (Nobuyoshi Nakada) 8 months ago

  • Has duplicate Bug #20308: `it` and numbered parameters do not work in `eval` added
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0