1、最常用的是each each_with_index
ss = [1,2,3,4,5]
ss.each do |s|
puts s
end
ss.each_with_index do |s,i|
puts ss[i]
end
2、case(switch)语句
case x
when "this"
func_this_that()
when "that"
func_this_that()
when "nothing"
# something different
end
# Example 1
x = ["case4"]
case x
when ["case1", "case2"]
puts "first case"
when ["case3", "case4", "case5"]
puts "second case"
when ["case6"]
puts "third case"
else
puts "not matched"
end
# Returns: "second case"
# Example 2
x = [6]
case x
when [1, 2]
puts "first case"
when [3, 4, 5]
puts "second case"
when [6]
puts "third case"
else
puts "not matched"
end
# Returns: "third case"
3、for 循环
for s in ss
puts s
end
4、……