문제

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?

도움이 되었습니까?

해결책

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))

다른 팁

A more shorter solution:

["1", "2", "3"].map(&:to_i)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top