Bug #7406

English.rb says that $_ is thread-local, but it is frame-local

Added by Charles Nutter over 1 year ago. Updated over 1 year ago.

[ruby-core:49619]
Status:Closed
Priority:Normal
Assignee:Yusuke Endoh
Category:-
Target version:2.0.0
ruby -v:2.0.0preview1 Backport:

Description

system ~/projects/jruby/gist-4110634 $ jirb
irb(main):001:0> $_ = 'foo'
=> "foo"
irb(main):002:0> def blah; p $_; end
=> nil
irb(main):003:0> p $_
"foo"
=> "foo"
irb(main):004:0> blah
nil
=> nil

Not thread-local.

Associated revisions

Revision 39010
Added by Yusuke Endoh over 1 year ago

  • lib/English.rb: Remove some confusing words from rdoc. [Bug #7406]

History

#1 Updated by Charles Nutter over 1 year ago

I guess this is a bit confusing, since it does also say it's scope-local. The thread-local part throws me off a bit. Is it thread-local or scope-local?

Here's the example again, this time actually running in 2.0.0.preview1:

system ~/projects/jruby $ irb-2.0.0
irb(main):001:0> $_ = 'foo'
=> "foo"
irb(main):002:0> def blah; p $_; end
=> nil
irb(main):003:0> p $_
"foo"
=> "foo"
irb(main):004:0> blah
nil
=> nil

#2 Updated by Yusuke Endoh over 1 year ago

  • Status changed from Open to Assigned
  • Assignee set to Yusuke Endoh
  • Target version set to 2.0.0

I think that "scope-local" normally implies "thread-local".
If you think it is confusing, I'll delete the comments, unless there is objection.

diff --git a/lib/English.rb b/lib/English.rb
index 4fd53c5..44baf17 100644
--- a/lib/English.rb
+++ b/lib/English.rb
@@ -119,7 +119,7 @@ alias $CHILD_STATUS $?
# and $1 to $9 are all derived from
# $~. Assigning to $~ changes the values of these
# derived variables. This variable is local to the current
-# scope. Thread local.
+# scope.
alias $LAST_MATCH_INFO $~

# If set to any value apart from +nil+ or +false+, all pattern matches
@@ -135,21 +135,21 @@ alias $ARGV $*

# The string matched by the last successful pattern
# match. This variable is local to the current
-# scope. Read only. Thread local.
+# scope. Read only.
alias $MATCH $&

# The string preceding the match in the last
# successful pattern match. This variable is local to
-# the current scope. Read only. Thread local.
+# the current scope. Read only.
alias $PREMATCH $`

# The string following the match in the last
# successful pattern match. This variable is local to
-# the current scope. Read only. Thread local.
+# the current scope. Read only.
alias $POSTMATCH $'

# The contents of the highest-numbered group matched in the last
# successful pattern match. Thus, in "cat" =~ /(c|a)(t|z)/,
# $+ will be set to "t". This variable is local to the
-# current scope. Read only. Thread local.
+# current scope. Read only.
alias $LAST_PAREN_MATCH $+

Yusuke Endoh mame@tsg.ne.jp

#3 Updated by Yusuke Endoh over 1 year ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r39010.
Charles, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • lib/English.rb: Remove some confusing words from rdoc. [Bug #7406]

Also available in: Atom PDF