Reputation: 171
I want to make it like in Python, 4 example:
print(
foobar,
footree,
foodrink
)
and it will be print in one line:
>>> "foobar, footree, foodrink"
In Ruby with the same code:
puts foobar,
footree,
foodrink
>>> "foobar"
... "footree"
... "foodrink"
Yes, I can do it with print, like this, but it looks ugly:
puts "foobar" +
"foobar" +
"foobar" +
>>> "foobar, footree, foodrink"
Thx in advance!
Edited. Now I have the following "Align the arguments of a method call if they span more than one line" and in terminal it output from a new line, I need it in one line.
Upvotes: 1
Views: 320
Reputation:
I'm making some assumptions about your various data types based on limited information given in your example, but the closest syntax I can come up with is using an array
([]
) along with p
and join
like so:
foobar = "foobar"
footree = "footree"
foodrink = "foodrink"
p [
foobar,
footree,
foodrink
].join(" ")
#=> "foobar footree foodrink"
Upvotes: 1
Reputation: 29766
>> a, b = "bar", "tree"
>> puts [a, b].join(", ")
bar, tree
or print
:
>> print a, ", ", b, "\n"
bar, tree
Upvotes: 1