Last active
September 28, 2015 14:56
-
-
Save nbfritz/7177de26826b92e199bd to your computer and use it in GitHub Desktop.
@ and @@ blog
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 SampleClass | |
# (#1) class-level setter and getter for a | |
def self.a=(value) | |
@@a = value | |
end | |
def self.a | |
@@a | |
end | |
# (#2) instance-level setter and getter for a | |
def a=(value) | |
@@a = value | |
end | |
def a | |
@@a | |
end | |
# (#3) class-level setter and getter for b | |
def self.b=(value) | |
@b = value | |
end | |
def self.b | |
@b | |
end | |
# (#4) instance-level setter and getter for b | |
def b=(value) | |
@b = value | |
end | |
def b | |
@b | |
end | |
# (#5) class- and instance-level attr_accessors | |
class << self | |
attr_accessor :c | |
end | |
attr_accessor :c | |
end | |
class SampleSubClassA < SampleClass; end | |
class SampleSubClassB < SampleClass; end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment