Skip to content

Instantly share code, notes, and snippets.

@urbanautomaton
Created October 30, 2012 09:15
Show Gist options
  • Save urbanautomaton/3979180 to your computer and use it in GitHub Desktop.
Save urbanautomaton/3979180 to your computer and use it in GitHub Desktop.
class A
attr_reader :fish
attr_writer :fish
private :fish=
def set_fish
fish = :carp
nil
end
end
class B
attr_reader :fish
attr_writer :fish
private :fish=
def some_public_method
self.fish = :chub
nil
end
end
#> a = A.new
#=> #<A:0x00000103482d90>
#> a.fish
#=> nil
#> a.fish = :barry
#NoMethodError: private method `fish=' called for #<A:0x000001034d3f10>
#> a.set_fish
#=> nil
#> a.fish
#=> nil
#> b = B.new
#=> #<B:0x00000103482d90>
#> b.fish
#=> nil
#> b.fish = :barry
#NoMethodError: private method `fish=' called for #<B:0x000001034d3f10>
#> b.set_fish
#=> nil
#> b.fish
#=> :chub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment