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.

    PHP

    $fruit = array('apple', 'orange');
    $result = end($fruit);
    var_export($result);
    // => 'orange'

    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.

    see also

echo ereg

Looking for Rails or PHP web application development, integration, and training?

Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.