Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
配列の場合、[1, 2, 3, 4],各要素を処理しているときに、配列の最後の要素にいることをどのように知ることができますか。
[1, 2, 3, 4],
arr = [1, 2, 3, 4] arr.each do |a| ... end
arr = [1, 2, 3, 4] l = arr.length - 1 arr.each_with_index do |a, i| if i == l ... else ... end end
arr = [1, 2, 3, 4] arr.each_with_index do |el, idx| if idx == arr.length - 1 # you're on the last element end end