Skip to content

Instantly share code, notes, and snippets.

@taea
Last active December 16, 2015 07:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save taea/5397960 to your computer and use it in GitHub Desktop.
配列を一定数とりだしてコンマでつなげて表示したい
-# @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