Created
April 6, 2016 23:54
-
-
Save chuck0523/8829cdac7dead0afd066b9d7a80aaac7 to your computer and use it in GitHub Desktop.
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
# 配列 | |
a = ['banana', 'strawberry', 'apple'] | |
# 一番文字列の長いものを返す | |
a.max_by { |x| x.length } # strawberry | |
# 引数に個数を指定できる。 | |
a.max_by(2) { |x| x.length } # [strawberry, banana] | |
# ちなみに、評価式はもちらん以下の書式でもOK | |
a.max_by &:length # strawberry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment