Created
September 29, 2015 14:17
-
-
Save elrayle/393f44e39542e0825d48 to your computer and use it in GitHub Desktop.
Test Ruby Classes and Eigenclasses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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