What are all the ways to output a string in Ruby?
# What are all the ways to output a string in Ruby? def hello_ruby greet = "Hello Ruby!" 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
greet = "Hello Ruby!"- # What are all the ways to output a string in Ruby?
- def hello_ruby
- greet = "Hello Ruby!"
print greet, ""puts greet$stdout.write greet +""$stdout.puts greet$stdout.print greet, ""(greet+"").each_char {|c| print c}- print greet, "
- "
- puts greet
- $stdout.write greet + "
- "
- $stdout.puts greet
- $stdout.print greet, "
- "
- $stdout << greet + "\n"
- (greet+"
- ").each_char {|c| print c}
- end
stdout = with_captured_stdout do hello_ruby end Test.assert_equals(stdout, (["Hello Ruby!\n"] * 7).join)
# TODO: TDD development by writing your own tests as you solve the kata.# These are some of the methods available:# Test.expect(boolean, [optional] message)# Test.assert_equals(actual, expected, [optional] message)# Test.assert_not_equals(actual, expected, [optional] message)#describe "Solution" do# it "should test for something" do# Test.assert_equals("actual", "expected")# end#end- stdout = with_captured_stdout do
- hello_ruby
- end
- Test.assert_equals(stdout, (["Hello Ruby!\n"] * 7).join)