-
-
Save AJFaraday/8e1896a506cb8206170358ffdec57411 to your computer and use it in GitHub Desktop.
here be dragons?
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
Array.new(6, 'eggs') | |
# => ["eggs", "eggs", "eggs", "eggs", "eggs", "eggs"] | |
# | |
# buuut | |
# | |
class Egg | |
attr_accessor :broken | |
end | |
a = Array.new(6, Egg.new) | |
# => [#<Egg:0x000000022d4090>, #<Egg:0x000000022d4090>, #<Egg:0x000000022d4090>, #<Egg:0x000000022d4090>, #<Egg:0x000000022d4090>, #<Egg:0x000000022d4090>] | |
a[0].broken = true | |
# => true | |
a | |
# => [#<Egg:0x000000022d4090 @broken=true>, #<Egg:0x000000022d4090 @broken=true>, #<Egg:0x000000022d4090 @broken=true>, #<Egg:0x000000022d4090 @broken=true>, #<Egg:0x000000022d4090 @broken=true>, #<Egg:0x000000022d4090 @broken=true>] |
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
a = Array.new(6) {Egg.new} | |
# => [#<Egg:0x000000023839a0>, #<Egg:0x00000002383978>, #<Egg:0x00000002383950>, #<Egg:0x00000002383928>, #<Egg:0x00000002383900>, #<Egg:0x000000023838d8>] | |
a[0].broken=true | |
# => true | |
a | |
# => [#<Egg:0x000000023839a0 @broken=true>, #<Egg:0x00000002383978>, #<Egg:0x00000002383950>, #<Egg:0x00000002383928>, #<Egg:0x00000002383900>, #<Egg:0x000000023838d8>] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment