Skip to content

Instantly share code, notes, and snippets.

@novikserg
Last active March 15, 2018 18:40
Show Gist options
  • Save novikserg/8e73a3d6af1954d338f1fe98e23cd1b5 to your computer and use it in GitHub Desktop.
Save novikserg/8e73a3d6af1954d338f1fe98e23cd1b5 to your computer and use it in GitHub Desktop.
Multiple attr_readers in Ruby
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