Ad
Code
Diff
  • # What are all the ways to output a string in Ruby?
    def hello_ruby
      greet = "Hello Ruby!"
    
      print           greet, "\n"
      puts            greet
      print           "#{greet}\n"
      puts            "#{greet}"
      $stdout.write   greet + "\n"
      $stdout.puts    greet
      $stdout.print   greet, "\n"
      $stdout <<      greet + "\n"
      (greet+"\n").each_char {|c| print c}
    end
    • # What are all the ways to output a string in Ruby?
    • def hello_ruby
    • greet = "Hello Ruby!"
    • print greet, "\n"
    • puts greet
    • print "#{greet}\n"
    • puts "#{greet}"
    • $stdout.write greet + "\n"
    • $stdout.puts greet
    • $stdout.print greet, "\n"
    • $stdout << greet + "\n"
    • (greet+"\n").each_char {|c| print c}
    • end