tags:

views:

50

answers:

2

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.

+5  A: 

This should do it:

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

"755".to_i(8) == 0755
# => true
Todd Yandell
Fantastic, did this test in irb and got "true" -> 0755 == "755".to_i(8)
Christoffer
Just added that to my answer so people understand what this is for.
Todd Yandell
A: 
def append_zero_to_string(string)
    0.to_s + string
end 
Sam