例如,我有下面的html,我需要让它重复多次。如果不使用止痛药和其他东西,我怎么能轻易地重复呢?
<div>This is a div</div>我在找这样的东西:
<%= repeat 4 times %>
<div>This is a div</div>
<% end %>发布于 2014-11-29 16:20:51
使用Ruby times方法:
<% 4.times do %>
<div>This is a div</div>
<% end %>发布于 2014-11-29 16:23:39
#!/usr/bin/env ruby
3.times do
puts "This will be printed 3 times"
end
print "Enter a number: "
num = gets.chomp.to_i
num.times do
puts "Ruby is great!"
end 这是红宝石时代循环的一个例子。希望它能帮上忙
https://stackoverflow.com/questions/27204278
复制相似问题