ruby code example(11)

ruby code example(11)
#############################################
##闭包的一个用法
animals = %w( ant bee cat dog elk ) # create an array
animals.each {|animal| puts animal } # iterate over the contents


#############################################
  def call_block
puts "Start of method"
yield ##执行传入的参数.这里为"In the block"
yield
puts "End of method"
end

call_block { puts "In the block" }

##############################################

你可能感兴趣的:(ruby code example(11))