Convert PHP code into Ruby!
RSS icon Email icon Home icon
  • count

    Posted on April 11th, 2009 RubyLove No comments

    Returns the number of elements in an array.

    PHP

    $a = array('first' => 1, 'second' => 2);
    echo count($a);
    // => 2

    Ruby

    my_array = [1, 2];
    puts my_array.length;
    # => 2

    Leave a reply