Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Latest commit

 

History

History
32 lines (25 loc) · 690 Bytes

File metadata and controls

32 lines (25 loc) · 690 Bytes

end

Ruby has no internal pointer in array objects like PHP. Because of this, there is no direct equivalent to PHP's end function.

Sometimes end is used to grab the last value of an array. We can do this in Ruby using the Array#last method.

{{code:php $fruit = array('apple', 'orange'); $result = end($fruit); var_export($result); // => 'orange' }}

{{code:ruby fruit = ["apple", "orange"] result = fruit.last # => "orange" }}

The last method does not work for associative key/value hashes in Ruby since hashes are unordered collections.

{{related: array/current array/each array/prev array/next
array/reset }}