Biswajit Das Biswajit Das - 1 year ago 76
Ruby Question

Ruby convert string array to string

I have a ruby string array value and i want to get it as string value. I am using ruby with chef recipe. Running in windows platform. Code-

version_string ='some.exe -version').run_command
extract_var = version_string.stdout.to_s.lines.grep(/ver/)'version:'+ extract_var.to_s)

output is coming-

version 530
[2016-06-08T07:03:49+00:00] INFO: version ["version 530\r\n"]

I want to extract 530 string only.

Answer Source

As you want val = 720 and not val = "720" you can write

val = strvar.first.to_i
  #=> 720