Last active
August 29, 2015 14:06
-
-
Save spacemunkay/bd64926586df8f7278a6 to your computer and use it in GitHub Desktop.
Accessor confusion with Array Union
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 MyClass | |
attr_accessor :values, :uniq_values | |
def initialize(value) | |
self.uniq_values = ['default_value'] | |
self.values = ['default_value'] | |
copy_value(value) | |
add_value(value) | |
end | |
def copy_value(value) | |
uniq_values |= value | |
end | |
def add_value(value) | |
values << value | |
end | |
def run | |
puts "unique_values: #{uniq_values}" | |
puts "values: #{values}" | |
end | |
end | |
obj = MyClass.new('poop') | |
obj.run | |
# Expect 'unique_values' and 'values' to be the same | |
# OUTPUT: | |
# unique values: ["default_value"] | |
# values: ["default_value", "poop"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment