Project

General

Profile

Actions

Feature #16432

closed

Using `_1` inside `binding.irb` will cause unintended behavior

Added by osyo (manga osyo) almost 5 years ago. Updated almost 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:96332]

Description

Summary

Calling binding.irb in a block that uses _1 and using _1 in irb will cause unintended behavior.

Steps to reproduce

  1. Use _1 in block
  2. Use binding.irb in block
  3. Use block with _1 in binding.irb
# test.rb
proc {
  binding.irb
  _1
}.call 42
# binding.irb
irb> (1..10).map { _1 + _1 }

Expected behavior

irb> _1
 => 42
irb> (1..10).map { _1 + _1 }
 = > [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]

Actual behavior

  • Refers to the _1 of the block that called binding.irb
irb> _1
 => 42
irb> (1..10).map { _1 + _1 }
 = > [84, 84, 84, 84, 84, 84, 84, 84, 84, 84]

I think this is an unintended behavior for the user.


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #18558: Numbered arguments + evalClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0