Created
December 14, 2008 06:28
-
-
Save Sixeight/35641 to your computer and use it in GitHub Desktop.
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
require 'forwardable' | |
# A singleton class inspired by Primer class in library | |
class Class | |
# We need that method like this become a bultin | |
def metaclass; class << self; self end end | |
end | |
class Foo | |
class << self | |
extend Forwardable | |
_instance = Foo.new | |
define_method(:instance) { _instance } | |
# Primer class's cool technic with forwardable | |
def method_added(meth) | |
self.metaclass.def_delegator :instance, meth | |
end | |
private :new | |
end | |
def say | |
puts 'hello' | |
end | |
end | |
Foo.say #=> hello |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment