Skip to content

Instantly share code, notes, and snippets.

@phiggins
Created November 16, 2010 23:57
Show Gist options
  • Save phiggins/702755 to your computer and use it in GitHub Desktop.
Save phiggins/702755 to your computer and use it in GitHub Desktop.
Constant resolution across rubies
class TopLevel
module Constants
HelloWorld = "Hello, World!"
def self.hello_world
puts HelloWorld
end
end
end
TopLevel::Constants.class_eval do
def self.new_hello_world
puts HelloWorld
end
end
TopLevel::Constants.hello_world
TopLevel::Constants.new_hello_world
=begin
phiggins@gibson:/tmp$ ruby -v const_resolution.rb
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
Hello, World!
Hello, World!
phiggins@gibson:/tmp$ ruby -v const_resolution.rb
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
Hello, World!
const_resolution.rb:12:in `new_hello_world': uninitialized constant HelloWorld (NameError)
from const_resolution.rb:17
phiggins@gibson:/tmp$ ruby -v const_resolution.rb
jruby 1.5.5 (ruby 1.8.7 patchlevel 249) (2010-11-10 4bd4200) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_22) [amd64-java]
Hello, World!
const_resolution.rb:12:in `new_hello_world': uninitialized constant HelloWorld (NameError)
from const_resolution.rb:17
phiggins@gibson:/tmp$ ruby --1.9 -v const_resolution.rb
jruby 1.5.5 (ruby 1.9.2dev trunk 24787) (2010-11-10 4bd4200) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_22) [amd64-java]
Hello, World!
const_resolution.rb:12:in `new_hello_world': uninitialized constant HelloWorld (NameError)
from const_resolution.rb:17
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment