On Fri, Nov 25, 2016 at 1:49 AM, Samuel Williams
<space.ship.traveller / gmail.com> wrote:

> 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?

I'd go with

buffer = "".dup

Kind regards

robert

-- 
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>