Created
January 11, 2012 17:11
-
-
Save JonnieCache/1595656 to your computer and use it in GitHub Desktop.
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 | |
class << self #anything inside this is executed in the context of the class object | |
attr_accessor :bar | |
def upcase_bar | |
@bar.upcase | |
end | |
end | |
def self.downcase_bar #also, in the class definition, self also refers to the class object | |
@bar.downcase | |
end | |
end | |
Foo.bar = "lol" | |
Foo.bar | |
=> "lol" | |
Foo.upcase_bar | |
=> "LOL" | |
Foo.downcase_bar | |
=> "lol" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment