Skip to content

Instantly share code, notes, and snippets.

@gnufied
Created April 19, 2013 16:20
Show Gist options
  • Save gnufied/5421414 to your computer and use it in GitHub Desktop.
Save gnufied/5421414 to your computer and use it in GitHub Desktop.
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