# Re: Some ugly code (again)

**URL:** <https://www.ruby-forum.com/t/re-some-ugly-code-again/96105>\
**Category:** Ruby\
**Created:** [June 26, 2006, 11:15am UTC](https://www.ruby-forum.com/t/re-some-ugly-code-again/96105 "2006-06-26T11:15:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeSSSSaS\_Botp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ecd19e/32.png) [@PeSSSSaS\_Botp](https://www.ruby-forum.com/u/PeSSSSaS_Botp)\
**Post date:** [June 26, 2006, 11:15am UTC](https://www.ruby-forum.com/t/re-some-ugly-code-again/96105/1 "2006-06-26T11:15:25Z")

</div>

fr Arnaud:

# Can I do nicer than:

# 

# {1…y}.each do |y|

# {1…x}.each do |x|

# the\_name = name + y.to\_s + x.to\_s

# end

# end

your code is already nice. it is readable to me.  
“nicer” is difficult to measure 🙂

if you do not like the “…” notation and  
if you do not like the to\_s conversion,

you can eg do something like,

> cat test.rb

y=3  
x=4

1.upto(y) do |i|  
1.upto(x) do |j|  
puts “rack#{i}#{j}”  
end  
end

or

y.times do |i|  
x.times do |j|  
puts “rack#{i+1}#{j+1}”  
end  
end

> ruby test.rb  
> rack11  
> rack12  
> rack13  
> rack14  
> rack21  
> rack22  
> rack23  
> rack24  
> rack31  
> rack32  
> rack33  
> rack34

kind regards -botp
