美文网首页
ruby-块

ruby-块

作者: CaesarsTesla | 来源:发表于2017-06-16 11:49 被阅读4次
=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