LoginSignup
0
0

More than 1 year has passed since last update.

Ruby lastメソッド

Posted at

lastメソッドとは

lastメソッドは配列の要素を取り出すときにその配列の中の最後の要素を取得するメソッド。
配列の要素がない場合はnilを返す。

lastメソッドの書き方

配列名.last
配列名.last(引数)
colors = ["red", "blue", "yello", "black"]
puts colors.last
puts colors.last(3)

Image from Gyazo

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0