配列を一定数とりだしてコンマでつなげて表示したい
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-# @usersからnameを5ことりだして,でつなげる | |
= @users[0..4].map(&:name).join(', ') | |
-#これらでもよい(というかこっちの方が実行効率がわずかによいらしい) | |
= @users[0, 5].map(&:name).join(', ') | |
= @users.take(5).map(&:name).join(', ') | |
= @users.first(5).map(&:name).join(', ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment