ruby - Array elements to integers -


i have array of strings containing numbers:

array = ["1", "2", "3"] 

i want convert every string in array integer.

array.each { |n| n.to_i } not work, because

p array.inject(:+) 

returns "123" (string) rather 6 (integer)

array = ["1", "2", "3"] new_array = array.map { |n| n.to_i } p new_array.inject(:+) => 6 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -