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

    Posted on July 10th, 2009 RubyLove 2 comments

    The lcfirst() function returns a string, with the first character in lower case - only if the first character is alphabetic.

    PHP

    echo lcfirst("Java is OK.");
    => // java is OK.

    Ruby

    my_string = "Java is OK.";
     
    puts my_string[0,1].downcase + my_string[1..-1];
    => # java is OK.
     

    2 responses to “lcfirst”

    1. Not sure you want the semicolon at the end of the Ruby statement :)

    2. Ruby has the ‘minimal code’ approach and makes the semi-colon optional.

      I think PHP developers are more comfortable ending with semi-colon - Im not sure if this is a good thing, or if forcing them to move to Ruby standards is better.

    Leave a reply