current

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

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

    PHP

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

    Ruby

    fruit = ["apple", "orange"]
    result = fruit.first
    # => "apple"

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

    see also

crypt dirname

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.