cant covert array of string in integers

hi,

irb(main):001:0> str=“1500,my sql,date 2500,my sql,date”
=> “1500,my sql,date 2500,my sql,date”
irb(main):002:0> hi=str.scan(/^(\d+)/)
=>
[[“1500”]]
irb(main):005:0> hi[0]
=> [“1500”]
irb(main):006:0> hi[0].to_i
NoMethodError: undefined method `to_i’ for [“1500”]:Array
from (irb):6
irb(main):007:0> hi[0][0].to_i
=> 1500
irb(main):008:0>

the problem is you are getting arrays of arrays

i just modified some part of your code

1)hi=str.scan(
/(\d+)/)
2)hi.inject(0){|sum, element|(sum.to_i)+(element[0].to_i)}

i also did

irb(main):016:0> hi=str.scan(/(\d+)/).flatten

=> [“1500”, “234”, “2500”]
irb(main):017:0> hi.inject(0){|sum, element|(sum.to_i)+(element.to_i)} #your code
=> 4234

i hope this helps

regards
gaurav