3 ms·
I'm not sure if this the question you're asking but in Ruby the program fails. gsub! is a method of String that mutates the object (vs gsub which returns a new
by pmontra 8y ago
I'm not sure if this the question you're asking but in Ruby the program fails.
gsub! is a method of String that mutates the object (vs gsub which returns a new string)
freeze is a method that makes immutable the object it's called upon.
2.3.0 :001 > def replace_a_with_b(s)
2.3.0 :001?> s.gsub!("a", "b")
2.3.0 :001?> end
=> :replace_a_with_b
2.3.0 :002 > replace_a_with_b("abc")
=> "bbc"
2.3.0 :003 > replace_a_with_b("abc".freeze)
RuntimeError: can't modify frozen String
from (irb):20:in `gsub!'
from (irb):20:in `replace_a_with_b'
from (irb):23
from /home/me/.rvm/rubies/ruby-2.3.0/bin/irb:11:in `<main>'
- XMPPwocky 8y agowait, so you can either have one "owner" and transfer ownership between domains (via move) or have shared, but immutable, ownership? Hm. Who let the Rust folks in?
- pmontra 7y agoLanguages cross pollinate. Eventually every language going through the message passing route will reimplement the Erlang VM and OTP...