Skip to content

Instantly share code, notes, and snippets.

@JonnieCache
Created January 11, 2012 17:11
Show Gist options
  • Save JonnieCache/1595656 to your computer and use it in GitHub Desktop.
Save JonnieCache/1595656 to your computer and use it in GitHub Desktop.
class instance variables
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