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
2010-08-20 06:41:55
Fantastic, did this test in irb and got "true" -> 0755 == "755".to_i(8)
Christoffer
2010-08-20 06:43:34
Just added that to my answer so people understand what this is for.
Todd Yandell
2010-08-20 06:44:49