From: engineersmnky@... Date: 2014-07-31T16:21:33+00:00 Subject: [ruby-core:64146] [ruby-trunk - Bug #10103] Unable to refine class with CONSTANT Issue #10103 has been updated by Mike Hein. I would like to also mention that this impacts class_variables as well ~~~ module Foobar @@baz = "boom" refine String do @@foo = "bar" def foobar @@foo end def bazical @@baz end end end using Foobar Foobar.class_variables #=> [:@@baz, :@@foo] "".bazical #=> "boom" "".foobar #=> "bar" ~~~ The first one I understand since the block can utilize variables and methods outside of itself. The second one really confuses me as I didn't expect it to skip over String and end up in Foobar. It also does not raise any warning about `warning: class variable access from toplevel`. Just as I would have expected constants to raise a `SyntaxError` for dynamic assignment. Instance variables seem to be ignored all together from what I can see. ---------------------------------------- Bug #10103: Unable to refine class with CONSTANT https://bugs.ruby-lang.org/issues/10103#change-48151 * Author: Kyle Decot * Status: Open * Priority: Normal * Assignee: * Category: core * Target version: current: 2.2.0 * ruby -v: 2.1.1 * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN ---------------------------------------- When refining a class (such as `String` in the following example) it is impossible to assign a constant. The constant will get attached to the module containing the refinement instead of the refined class. When inside of a `refine` block constants should get assigned to that class. ~~~ module Foobar refine String do FOO = "BAR" def foobar "foobar" end end end using Foobar puts "".class::FOO # => uninitialized constant String::FOO (NameError) puts "".foobar # => "foobar" ~~~ -- https://bugs.ruby-lang.org/