📜  红宝石block_given?方法 - Ruby 代码示例

📅  最后修改于: 2022-03-11 15:04:50.190000             🧑  作者: Mango

代码示例1
# used when we call method with and without block from different places
def try
  if block_given?
    yield
  else
    "no block"
  end
end
try                  #=> "no block"
try { "hello" }      #=> "hello"
try do "hello" end   #=> "hello"