Created
January 21, 2014 22:53
-
-
Save benweint/8550146 to your computer and use it in GitHub Desktop.
String subclasses and encodings in Rubinius
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class BadString < String; end | |
original = (0..255).to_a.pack("C*").force_encoding("UTF-8") | |
subclass = BadString.new(original) | |
round_tripped = subclass.to_s | |
puts "encoding: original = #{original.encoding}, subclass = #{subclass.encoding}, round_tripped = #{round_tripped.encoding}" | |
puts "valid_encoding? original = #{original.valid_encoding?}, subclass = #{subclass.valid_encoding?}, round_tripped = #{round_tripped.valid_encoding?}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment