Created
April 19, 2013 16:20
-
-
Save gnufied/5421414 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
module Foo | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def metaclass; class << self; self; end; end | |
def hello(name = nil) | |
if name | |
self.class_variable_set(:@@name, name) | |
else | |
self.class_variable_defined?(:@@name) ? self.class_variable_get(:@@name) : nil | |
end | |
end | |
end | |
end | |
class Bar | |
include Foo | |
end | |
class Baz | |
include Foo | |
end | |
class Bleh < Bar | |
end | |
Bar.hello("heer") | |
puts Bar.hello() | |
puts Bleh.hello | |
p Baz.hello | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment