ruby-块

2017-06-16  本文已影响4人  CaesarsTesla
=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代码块'
上一篇 下一篇

猜你喜欢

热点阅读