Created
May 14, 2011 00:35
-
-
Save mgreenly/971546 to your computer and use it in GitHub Desktop.
ruby 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
class Foo | |
# create class instance variables | |
class << self; | |
attr_accessor :bar; | |
end | |
#initialize class instance variables | |
@bar = 42 | |
# use class instance variables in class methods | |
def self.inc_bar | |
@bar += 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment