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

    Posted on June 19th, 2009 RubyLove No comments

    The rtrim function strips whitespace (or other characters) from the end of a string.

    PHP

    echo rtrim('Work Hard. Play Harder.', ' Play Harder.');
    => // 'Work Hard.'

    Ruby

    substitute = 'Play Harder.';
     
    puts "Work Hard. Play Harder.".gsub(/[#{substitute}]+$/, '')
    => # 'Work Hard.'

    Leave a reply