Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

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"
Source by apidock.com #
 
PREVIOUS NEXT
Tagged: #ruby #method
ADD COMMENT
Topic
Name
9+6 =