M
Mike Hall
Question: Should String.upcase! work on a segment of a string?
We can assign to a sub-string, so I thought that a bang-method might also work on a sub-string.
s = 'AA11zz' # define a string
Are there edge cases where this wouldn't be appropriate?
We can assign to a sub-string, so I thought that a bang-method might also work on a sub-string.
s = 'AA11zz' # define a string
=> "ZZ" # yeah, ok, the new string is changed, but...s[4..5].upcase! # try to change part of it
=> "AA11zz" # the original string wasn't affected
=> "ZZ"s[4..5] = s[4..5].upcase # so, do it by-hand
=> "AA11ZZ"s # and it's ok
Are there edge cases where this wouldn't be appropriate?