Skip to content

Instantly share code, notes, and snippets.

@brixen
Created October 26, 2012 16:36
Show Gist options
  • Select an option

  • Save brixen/3959786 to your computer and use it in GitHub Desktop.

Select an option

Save brixen/3959786 to your computer and use it in GitHub Desktop.
sasha:rubinius brian$ irb
1.9.3p286 :001 > "abc".force_encoding('ascii-8bit') + "\xff".force_encoding('us-ascii')
=> "abc\xFF"
1.9.3p286 :002 > a = "\x12:\xFF\xB6\xB3\x8D\xB8\x03".force_encoding('ascii-8bit')
=> "\x12:\xFF\xB6\xB3\x8D\xB8\x03"
1.9.3p286 :003 > b = "\x98~<\x84\xC3F|X".force_encoding 'us-ascii'
=> "\x98~<\x84\xC3F|X"
1.9.3p286 :004 > a + b
Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and US-ASCII
from (irb):4
from /Users/brian/.rvm/rubies/ruby-1.9.3-p286/bin/irb:16:in `<main>'
1.9.3p286 :005 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment