Analysis
The problem in your code is the use of Integer#times. Per the documentation, the #times method:
[i]terates the given block int
times, passing in values from zero to int - 1
.
So, here is your given code, with comments:
height.to_i.times do |i| # when `height = 5`, equivalent to `(0..4).each`
output << "*" * i # will be "" on the first pass when i == 0
output << "\n"
end
Solution
In this case, you should use the Integer#upto method instead of Integer#times, with 1
as your starting value. Consider the following example, rewritten as a one-liner you can run from the command prompt:
$ ruby -e '1.upto(Integer(ARGV[0])) { |i| puts "*" * i }' 5
*
**
***
****
*****
In addition to giving the expected results on standard output, it also does away with string mutation, declaring an output variable, and other non-essentials. The use of Kernel#Integer will also raise an exception if ARGV[0] can't be cast as an integer, rather introducing subtle bugs such as when ARGV[0] == ""
.