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.
のようなRubyの配列があり["dog", "cat", bat"]ます。各要素が特定のメソッドに渡される配列を取得するにはどうすればよいですか? たとえば、メソッドが入力文字列を逆にすると、["god", "tac", "tab"]. 要素を反復処理し、それらをメソッドに渡し、結果を配列に入れるのは簡単です。しかし、もっと短い方法はありますか?
["dog", "cat", bat"]
["god", "tac", "tab"]
編集:元の配列を変更したくありません。
["dog", "cat", "bat"].map { |word| word.reverse }
また
["dog", "cat", "bat"].map &:reverse