I'm getting an unexpected return value with this code:
str = ''; 'abc'.chars.map {|c| str<<c}
Expected output:
["a", "ab", "abc"]
Actual output:
["abc", "abc", "abc"]
Adding a puts(str) for debugging:
str = ''; 'abc'.chars.map {|c| puts(str); str<<c}
a
ab
=> ["abc", "abc", "abc"]
Why is the above code not returning the expected output? Thanks.
# frozen_string_literal: truedirective. It will prevent you from using destructive methods likeString#<<. There is a performance penalty in some scenarios, but the tradeoff is worth it for most teams.