H
Heesob Park
Hi all,
I like to set caller's $_ variable in a method, but it did't work for me.
Consider this:
def foo
puts "$_ = #{$_.inspect} enter foo"
$_ = 'def'
puts "$_ = #{$_.inspect} exit foo"
end
$_ = 'abc'
puts "$_ = #{$_.inspect} before foo"
foo
puts "$_ = #{$_.inspect} after foo"
The result is:
$_ = "abc" before foo
$_ = nil enter foo
$_ = "def" exit foo
$_ = "abc" after foo
I noticed $_ is is local to the current scope.
Is it impossible to set the caller's $_ variable in a method without
using binding and eval?
Thanks,
Park Heesob
I like to set caller's $_ variable in a method, but it did't work for me.
Consider this:
def foo
puts "$_ = #{$_.inspect} enter foo"
$_ = 'def'
puts "$_ = #{$_.inspect} exit foo"
end
$_ = 'abc'
puts "$_ = #{$_.inspect} before foo"
foo
puts "$_ = #{$_.inspect} after foo"
The result is:
$_ = "abc" before foo
$_ = nil enter foo
$_ = "def" exit foo
$_ = "abc" after foo
I noticed $_ is is local to the current scope.
Is it impossible to set the caller's $_ variable in a method without
using binding and eval?
Thanks,
Park Heesob