I'm currently studying refinements in Ruby 2.1.1, and I am running into something weird. I am trying to clarify the String class and define a constant named FOO .
sandbox.rb
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"
This gives me an uninitialized constant String::FOO (NameError) . However, I can call "".foobar , which makes me believe that I am in the right volume.
Which is strange, if I open the String class and define FOO , I get a different result.
sandbox.rb
class String FOO = "BAR" end puts "".class::FOO # => "BAR"
Why not a clarifying version of this work, as I expect?
ruby
Kyle decot
source share