Well in ruby shape making is pretty easy compared to some of the other languages that require a lot more syntax. Here is a rough example of building an X width diamond...
ruby
# Prompt for the number of columns in the middle of a diamond
puts "Enter the number of columns for the diamond: "
count = gets.chomp.to_i
# Loop from 1 up to the count they entered
# In each loop we loop from that many spaces for the row, then that many asterisks
# End with a new line. This forms the top of the diamond.
1.upto(count) do |i|
i.upto(count - 1) { print " " }
i.times { print " *" }
print "\n"
end
# Subtract 1 so we don't double up the middle row
count = count - 1
# Now go from count down to 1
count.downto(1) do |i|
i.upto(count) { print " " }
i.times { print " *" }
print "\n"
end
Essentially we ask for a number, loop from 1 to that number and construct the proper number of spaces and asterisks for each level until we get to the middle. Then we do the reverse to form the bottom half of the diamond.
As with all ruby this can be crunched down even further, but I wanted to keep this open enough so it wasn't too cryptic.
Hope it helps!
"At DIC we be diamond building with ruby code ninjas... we are the jewelers of the coding world."