Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Last active December 5, 2015 14:33
Show Gist options
  • Save YumaInaura/d15f7edc2507305416f5 to your computer and use it in GitHub Desktop.
Save YumaInaura/d15f7edc2507305416f5 to your computer and use it in GitHub Desktop.
Ruby | first / last / begin / end / min / max の違い ref: http://qiita.com/Yinaura/items/77cc63a335b618fc5e90
[5,4,3,2,1].first
# => 5
[5,4,3,2,1].last
# => 1
(5..1).begin
# => 5
(5..1).first
# => 5
[5,4,3,2,1].begin
# => NoMethodError: undefined method `begin' for [5, 4, 3, 2, 1]:Array
(5..1).end
# => 1
(5..1).last
# => 1
[5,4,3,2,1].end
# => NoMethodError: undefined method `end' for [5, 4, 3, 2, 1]:Array
[5,4,-3,2,1].min
# => -3
[5,4,30,2,1].max
# => 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment