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

    Posted on April 23rd, 2009 RubyLove 1 comment

    Output a formatted string.

    PHP

    $format = 'There are %d monkeys in the %s';
    printf($format, 5, 'tree');
    // => There are 5 monkeys in the tree

    Ruby

    my_string = 'There are %d monkeys in the %s';
    printf(my_string, 5, 'tree');
    # => There are 5 monkeys in the tree
     

    One response to “printf”

    1. RUBY:

      puts ‘There are %d monkeys in the %s’ % [5, 'tree']

    Leave a reply