ruby-块
=begin
def test
puts "在test方法内"
yield
puts "你又回到了test方法内"
yield
end
test{puts "你再块内"}
=end
=begin
def test
yield 5
puts "在test方法内"
yield 100
end
test {|i| puts i}
=end
=begin
def test
yield 2,8
puts "在test方法内"
yield 3,7
end
test{|a,b| puts"你在#{a}.#{b}"}
=end
=begin
def test
yield
end
test{puts 'hi'}
=end
=begin
def test(&block)
block.call
end
test {puts 'hello®'}
=end
BEGIN{
puts 'BEGIN 代码块'
}
END {
puts 'END代码块'
}
puts 'MAIN代码块'
本文标题:ruby-块
本文链接:https://www.haomeiwen.com/subject/mxnpqxtx.html
网友评论