Created
February 18, 2013 11:48
-
-
Save Wardrop/4976817 to your computer and use it in GitHub Desktop.
No means to access outer class from singleton class.
This file contains 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
# Doesn't work; needs reference to outer class object. | |
class SomeClass | |
class << self | |
extend Delegate | |
def hash | |
@hash ||= {} | |
end | |
delegate hash, :[]=, :has_key?, :each | |
end | |
end | |
# Works because everything is done in the outer class object. | |
class SomeClass | |
class << self | |
def hash | |
@hash ||= {} | |
end | |
end | |
extend Delegate | |
delegate hash, :[]=, :has_key?, :each | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment