# 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
stdout = with_captured_stdout do hello_ruby end Test.assert_equals(stdout, (["Hello Ruby!\n"] * 9).join)
- stdout = with_captured_stdout do
- hello_ruby
- end
Test.assert_equals(stdout, (["Hello Ruby!"] * 7).join)- Test.assert_equals(stdout, (["Hello Ruby!
- "] * 9).join)