Multiplication Operator
The multiplication operator (*
) can multiple (some) objects. Yep, objects, not just numbers. This, of course, depends on the Object#*
method being implemented for that particular object.
Not quite what you're looking for? See the Asterisk page for other ways that the asterisk symbol is used.
Let's look at a few useful examples of multiplying things.
# Integer multiplication
> 5 * 4
=> 20
# String multiplication
> 'ha' * 5
=> "hahahahaha"
# Array multiplication
> (["Ho!"] * 3).join(' ')
=> "Ho! Ho! Ho!"
We can multiple strings when quickly putting together some puts debugging statements.
puts '#' * 60
puts "Debug: #{record.errors}"
puts '#' * 60