Hello.
When preparing for immutable strings by default, I changed my code from
buffer = ""
to
buffer = String.new
However, an unintended side effect of this was the encoding:
2.3.1 :001 > "".encoding
=> #<Encoding:UTF-8>
2.3.1 :002 > String.new.encoding
=> #<Encoding:ASCII-8BIT>
I'm replacing `""` with `String.new(encoding: Encoding::UTF_8)` but
wondering what exactly is the best practice here going forward?
Kind regards,
Samuel
Hello.
Isn't it mode convenient to use
str = ''.freeze?
Rubocop gives advises with #freeze
Just if you want to keep the string empty. Otherwise, you will not be able
to modify it
···
On Sat, Nov 26, 2016, 11:45 AM Aleksey Ivanov <ialexxei@gmail.com> wrote:
Hello.
Isn't it mode convenient to use
str = ''.freeze?
Rubocop gives advises with #freeze
Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
--
--
Sébastien Puyet