Created
October 24, 2018 11:10
-
-
Save Marahin/069586d4fd809aae99e9967c11bbc04c to your computer and use it in GitHub Desktop.
Are fridge contents frozen or not?
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
arr = ["john", "alice", "philip"] | |
=> ["john", "alice", "philip"] | |
arr.map!(&:upcase) # works, array not frozen | |
=> ["JOHN", "ALICE", "PHILIP"] | |
arr | |
=> ["JOHN", "ALICE", "PHILIP"] | |
arr.freeze | |
=> ["JOHN", "ALICE", "PHILIP"] | |
arr.map!(&:downcase) # doesnt work, array is frozen | |
FrozenError: can't modify frozen Array | |
from (pry):5:in `map!' | |
arr.map(&:downcase!) # works, array is frozen, but particular objects inside are not | |
=> ["john", "alice", "philip"] | |
arr | |
=> ["john", "alice", "philip"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment