Skip to content

Instantly share code, notes, and snippets.

@dtakahas
Created August 9, 2016 23:51
Show Gist options
  • Save dtakahas/dcf478cd3f68420dd02b2810c78bb55f to your computer and use it in GitHub Desktop.
Save dtakahas/dcf478cd3f68420dd02b2810c78bb55f to your computer and use it in GitHub Desktop.
Ruby String Encoding
2.1.5 :001 > utf = "".force_encoding("UTF-8")
=> ""
2.1.5 :002 > utf.encoding
=> #<Encoding:UTF-8>
2.1.5 :003 > ascii = "".force_encoding("ASCII-8BIT")
=> ""
2.1.5 :004 > ascii.encoding
=> #<Encoding:ASCII-8BIT>
2.1.5 :005 > example = "thisIsMyPath".force_encoding("UTF-8")
=> "thisIsMyPath"
2.1.5 :006 > example.encoding
=> #<Encoding:UTF-8>
2.1.5 :007 > example1 = ascii + example
=> "thisIsMyPath"
2.1.5 :008 > example2 = utf + example
=> "thisIsMyPath"
2.1.5 :009 > example1.encoding
=> #<Encoding:ASCII-8BIT>
2.1.5 :010 > example2.encoding
=> #<Encoding:UTF-8>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment