Skip to content

Instantly share code, notes, and snippets.

@ptagell
Created October 10, 2015 04:13
Show Gist options
  • Save ptagell/78929397ebdb6a079660 to your computer and use it in GitHub Desktop.
Save ptagell/78929397ebdb6a079660 to your computer and use it in GitHub Desktop.
irb(main):129:0> value_to_evaluate
=> "\u00001\u00004\u00009\u00003\u0000"
irb(main):130:0> puts value_to_evaluate
1493
=> nil
irb(main):131:0> value_to_evaluate == 1493
=> false
irb(main):132:0>
@ptagell
Copy link
Author

ptagell commented Oct 10, 2015

I have no idea why but this works

@value_to_evaluate = @power_values_to_push.first.delete("\000")

@yob
Copy link

yob commented Oct 10, 2015

Where is the data in value_to_evaluate coming from? It looks like it might be utf16, which isn't a very common encoding in ruby-land.

You could try this to mark it as UTF-16, then convert it to UTF-8 (which is more common and usable in ruby)

value_to_evaluate_utf8 = value_to_evaluate.force_encoding("UTF-16BE").encode("UTF-8")
value_to_evaluate_utf8.to_i == 1493

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment