Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
2 文字の単語から 15 文字までの単語で満たされた配列があるとします。配列から 3 文字の単語だけを取得するにはどうすればよいでしょうか?
a = ['aa', 'ab', 'ad', ... , 'zoogeographical'] b = [] a.each do |x| if x.length = 3 b.push(x) end end
もっと簡単な方法があるようです。
selectメソッドはあなたが探しているものだと思います:
select
a.select {|string| string.length == 3 }