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

    Posted on July 26th, 2009 RubyLove No comments

    The range() function creates an array containing a range of elements in PHP, however in Ruby the Range object is used to handle ranges of integers or strings.

    PHP

    $chars = range('a', 'c');
    print_r($chars);
    // => array(0 => 'a', 1 => 'b', 2 => 'c')

    Ruby

    chars = 'a'..'c'
    chars.each {|item| print "#{item}, " } 
    # => a, b, c,

    Leave a reply