Skip to content

Instantly share code, notes, and snippets.

@jonelf

jonelf/string.rb

Last active Dec 29, 2015
Embed
What would you like to do?
Testing the string operations mentioned in http://mortoray.com/2013/11/27/the-string-type-is-broken/
s = "lëon"
puts "Precomposed #{s}"
puts "Reverse #{s.reverse!}"
puts "First three #{s[0..2]}"
puts "Length: #{s.length.to_s}"
puts
s = "noe\u0308l"
puts "Decomposed #{s}"
puts "Reverse #{s.reverse!}"
puts "First three #{s[0..2]}"
puts "Length: #{s.length.to_s}"
puts
cats = "😸😾"
puts cats
puts "Length #{cats.length}"
puts "Substring after the first character #{cats.slice(1)}"
puts "Reverse #{cats.reverse}"
puts
s = "baffle"
puts s
puts "Upcase #{s.upcase}"
puts
puts "precomposed == decomposed"
s1 = "\u00F6"
s2 = "\u006F\u0308"
puts "=> #{s1 == s2}"
@jonelf

This comment has been minimized.

Copy link
Owner Author

@jonelf jonelf commented Nov 27, 2013

Outputs: https://dl.dropboxusercontent.com/u/26840/strings_output.png

Ruby knows nothing about the decomposed form but it's good with cats. :)

http://en.wikipedia.org/wiki/Precomposed_character

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.