Created
May 6, 2014 15:28
-
-
Save meltingice/bbf55db4d2ec2d10866f to your computer and use it in GitHub Desktop.
Best way to set class level data and access from instance?
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
class MyClass < Base | |
option 'value' | |
def some_method | |
puts option | |
end | |
end |
class Base
cattr_accessor :option
def option
self.class.option || super
end
end
Something like that, maybe?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm currently doing:
Which overwrites the instance method every time it's called to return the new value. This feels really hacky though. Any better ideas?