Last active
March 15, 2018 18:40
-
-
Save novikserg/8e73a3d6af1954d338f1fe98e23cd1b5 to your computer and use it in GitHub Desktop.
Multiple attr_readers in Ruby
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 FooBar | |
attr_reader :a, :b | |
def initialize | |
@a = 1 | |
@b = 2 | |
@c = 3 | |
end | |
def see_the_c | |
puts c | |
end | |
private | |
attr_reader :c | |
end | |
fb = FooBar.new | |
puts fb.a # => 1 | |
puts fb.b # => 2 | |
puts fb.c # => private method `c' called for #<FooBar:0x007fba7784eb88 @a=1, @b=2, @c=3> (NoMethodError) | |
fb.see_the_c # => 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment