Created
August 12, 2014 05:23
-
-
Save domgetter/966ccf3a52d1ff47747e to your computer and use it in GitHub Desktop.
How do I prevent the @children array from being changed outside the class since I only used attr_reader ?
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 Human | |
attr_reader :children | |
def initialize | |
@children = ["Joe", "Henry"] | |
end | |
end | |
#=> nil | |
human = Human.new | |
#=> #<Human:0x2a19bd8 @children=["Joe", "Henry"]> | |
human.children << "Mary" | |
#=> ["Joe", "Henry", "Mary"] | |
human | |
#=> #<Human:0x2a19bd8 @children=["Joe", "Henry", "Mary"]> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment