6

I want to convert an hex string value in a variable to int.

This works for a literal: "#{0xFF}".to_i

But with a var...?

Not working test (interpolation error):

_myvar = "FF"
"#{0x_myvar}".to_i
Mat
  • 2,156
  • 2
  • 16
  • 29

1 Answers1

6

Why not check the API documentation for String

"FF".to_i(16)
Oleh Prypin
  • 33,184
  • 10
  • 89
  • 99