PHP to Ruby
Convert PHP code into Ruby!
-
lcfirst
Posted on July 10th, 2009 2 commentsThe 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”
-
Not sure you want the semicolon at the end of the Ruby statement
-
RubyLove February 22nd, 2010 at 15:52
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
-


