Answers for "ruby method that takes a block"

0

ruby block_given? method

# 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"
Posted by: Guest on May-25-2021

Code answers related to "ruby method that takes a block"

Browse Popular Code Answers by Language