Domanda

So let's say I have an array of strings in C#, I could convert this array of strings to an array of integers using the following LINQ statement:

(new[] {"1", "2", "3"}).Select(x => int.parse(x))

Is there a Ruby equivalent to this?

È stato utile?

Soluzione

Not quite sure what Select means in C#, but converting an array of strings to array of integers is quite simple: ["1", "2", "3"].map(&method(:Integer))

Altri suggerimenti

A more shorter solution:

["1", "2", "3"].map(&:to_i)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top