mercredi 25 février 2015

Ruby converts integer to octal-escaped string instead of hex-escaped one. WHY?

I need:



"31ff".scan(/../).map { |x| x.hex.chr }
=> ["1", "\xff"]


But instead I get:



"31ff".scan(/../).map { |x| x.hex.chr }
=> ["1", "\377"]


OK, actually this is just because of:



"ff".hex.chr
=> "\x377"


But I want:



"ff".hex.chr
=> "\xff"


Where is my mistake? What is missing? Environment is HBase shell which is JRuby console.


Aucun commentaire:

Enregistrer un commentaire