New to ruby
If I have an Array
@sample_array
How do I display the attr_accessors in a table
This doesn’t seem to be the right way as it repeats the table each time
it iterates through the array.
Thanks,
John
@sample_array.each do |t|
puts “
”
puts"
#{t.name} |
#{t.address} |
#{t.city} |
#{t.state} | </
tr>"
puts “
â€
end
On Wed, Mar 10, 2010 at 4:35 PM, John W. [email protected]
wrote:
How do I display the attr_accessors in a table
This doesn’t seem to be the right way as it repeats the table each time
it iterates through the array.
puts “
”
@sample_array.each do |t|
puts"
"
end
puts “
#{t.name} |
#{t.address} |
#{t.city} |
#{t.state} |
”
Hey John,
You just need to move the table start and end outside of the each
statement. Everything inside the each block gets done for each item
in the array:
Do once
puts “
”
@sample_array.each do |t|
Do for every item in the array (make one row per item)
puts"
#{t.name} |
#{t.address} |
#{t.city} |
#{t.state} |
"
end
Do once
puts “
”
Rob K. wrote:
Hey John,
You just need to move the table start and end outside of the each
statement. Everything inside the each block gets done for each item
in the array:
Do once
puts “
”
@sample_array.each do |t|
Do for every item in the array (make one row per item)
puts"
#{t.name} |
#{t.address} |
#{t.city} |
#{t.state} |
"
end
Do once
puts �
�
Thank you all for your help. It makes sense now and works perfect!
John