Posted by Seamus on Thursday, September 30, 2010.

Ruby 1.9.2 Marshal.dump remembers string encoding

Ruby 1.9.2 remembers encoding when it marshals a string:

ruby-1.9.2-p0 > Marshal.dump('hi')
 => "\x04\bI\"\ahi\x06:\x06ET" 
ruby-1.9.2-p0 > require 'iconv'
=> true 
ruby-1.9.2-p0 > Marshal.dump(Iconv.conv('US-ASCII', 'UTF8', 'hi'))
=> "\x04\bI\"\ahi\x06:\x06EF"

Ruby 1.8 did not:

ruby-1.8.7-head > Marshal.dump('hi')
 => "\004\b\"\ahi" 
ruby-1.8.7-head > require 'iconv'
 => true 
ruby-1.8.7-head > Marshal.dump(Iconv.conv('US-ASCII', 'UTF8', 'hi'))
 => "\004\b\"\ahi"

What blog is this?

Safety in Numbers is Brighter Planet's blog about climate science, Ruby, Rails, data, transparency, and, well, us.

Who's behind this?

We're Brighter Planet, the world's leading computational sustainability platform.

Who's blogging here?

  1. Patti Prairie CEO