* [ruby-core:93791] [Ruby master Bug#4484] Class variables leak to Object when using class_eval
[not found] <redmine.issue-4484.20110309070557@ruby-lang.org>
@ 2019-07-15 16:51 ` merch-redmine
0 siblings, 0 replies; only message in thread
From: merch-redmine @ 2019-07-15 16:51 UTC (permalink / raw
To: ruby-core
Issue #4484 has been updated by jeremyevans0 (Jeremy Evans).
Backport set to 2.5: UNKNOWN, 2.6: UNKNOWN
Status changed from Open to Rejected
Description updated
Project changed from Ruby 1.8 to Ruby master
This is still true in master, but I believe this is expected behavior/spec. This is similar to constants:
```ruby
String.class_eval {A = 1}
Object::A
# => 1
```
If you want to scope constants or class variables, you need to reopen the class using `class` syntax:
```ruby
class String
@@string_class_variable = 'should be only in String'
A = 1
end
Object.class_variables.include? :@@string_class_variable
# => false
Object::A
# NameError (uninitialized constant A)
```
----------------------------------------
Bug #4484: Class variables leak to Object when using class_eval
https://bugs.ruby-lang.org/issues/4484#change-79540
* Author: pawel (Paweł P)
* Status: Rejected
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
=begin
The following irb session describes the problem:
>> String.class_eval { @@string_class_variable = 'should be only in String' }
=> "should be only in String"
>> "WTF?" if Object.class_variables.include? "@@string_class_variable"
=> "WTF?"
Tested on 1.8 and 1.9.
I've created the issue in "ruby-18" project because "ruby" project doesn't allow to create new issues.
=end
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-07-15 16:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <redmine.issue-4484.20110309070557@ruby-lang.org>
2019-07-15 16:51 ` [ruby-core:93791] [Ruby master Bug#4484] Class variables leak to Object when using class_eval merch-redmine
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).