Christoffer Christoffer - 3 months ago 14
Ruby Question

Ruby string to octal?

How can I convert "755" to 0755 in Ruby? I want to pass permissions to a method using a string and then convert it for chmod use.

Answer

This should do it:

"755".to_i(8)
# => 493

"755".to_i(8) == 0755
# => true