Skip to content

Instantly share code, notes, and snippets.

@Wardrop
Created February 18, 2013 11:48
Show Gist options
  • Save Wardrop/4976817 to your computer and use it in GitHub Desktop.
Save Wardrop/4976817 to your computer and use it in GitHub Desktop.
No means to access outer class from singleton class.
# 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