Skip to content

Instantly share code, notes, and snippets.

@elrayle
Created September 29, 2015 14:17
Show Gist options
  • Save elrayle/393f44e39542e0825d48 to your computer and use it in GitHub Desktop.
Save elrayle/393f44e39542e0825d48 to your computer and use it in GitHub Desktop.
Test Ruby Classes and Eigenclasses
class TestParent
MY_CONSTANT = "Hello"
class << self
MY_EIGAN_CONSTANT = "World"
end
end
class TestChild < TestParent
begin
puts "global: MY_CONSTANT=#{MY_CONSTANT}"
rescue Exception => e
puts "global: MY_CONSTANT... ### FAILS ###"
end
begin
puts "global: MY_EIGAN_CONSTANT=#{MY_EIGAN_CONSTANT}"
rescue Exception => e
puts "global: MY_EIGAN_CONSTANT... ### FAILS ###"
end
def self.test
# WORKS
begin
puts "self.test: MY_CONSTANT=#{MY_CONSTANT}"
rescue Exception => e
puts "self.test: MY_CONSTANT... ### FAILS ###"
end
begin
puts "self.test: MY_EIGAN_CONSTANT=#{MY_EIGAN_CONSTANT}"
rescue Exception => e
puts "self.test: MY_EIGAN_CONSTANT... ### FAILS ###"
end
end
class << self
def eigentest
# FAILS
begin
puts "class << self.eigentest: MY_CONSTANT=#{MY_CONSTANT}"
rescue Exception => e
puts "class << self.eigentest: MY_CONSTANT... ### FAILS ###"
end
begin
puts "class << self.eigentest: MY_EIGAN_CONSTANT=#{MY_EIGAN_CONSTANT}"
rescue Exception => e
puts "class << self.eigentest: MY_EIGAN_CONSTANT... ### FAILS ###"
end
end
end
end
TestChild.test
TestChild.eigentest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment