Created
November 5, 2013 16:24
-
-
Save Tonkpils/7321671 to your computer and use it in GitHub Desktop.
Showing an example of class instance variables.
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
module Bar | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
def event_name | |
self.class.event | |
end | |
module ClassMethods | |
def event_name(name) | |
@event_name = name.to_sym | |
end | |
def event | |
@event_name | |
end | |
end | |
end | |
class Foo | |
include Bar | |
end | |
class Baz < Foo | |
event_name :cool | |
end | |
Baz.event | |
#=> :cool | |
Baz.new.event_name | |
#=> :cool |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment