block_name{
statement1
statement2
..........
}
#!/usr/bin/ruby
def test
puts "You are in the method"
yield
puts "You are again back to the method"
yield
end
test {puts "You are in the block"}
You are in the method You are in the block You are again back to the method You are in the block
#!/usr/bin/ruby
def test
yield 5
puts "You are in the method test"
yield 100
end
test {|i| puts "You are in the block #{i}"}
You are in the block 5 You are in the method test You are in the block 100
test {|i| puts "You are in the block #{i}"}
puts "You are in the block #{i}"
You are in the block 5
yield a, b
test {|a, b| statement}
#!/usr/bin/ruby
def test
yield
end
test{ puts "Hello world"}
#!/usr/bin/ruby
def test(&block)
block.call
end
test { puts "Hello World!"}
This will produce following result:
Hello World!
#!/usr/bin/ruby
BEGIN {
# BEGIN block code
puts "BEGIN code block"
}
END {
# END block code
puts "END code block"
}
# MAIN block code
puts "MAIN code block"
BEGIN code block MAIN code block END code block
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有