We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def block_message_printer
message = "Welcome to Block Message Printer"
if block_given?
yield
end
puts "But in this function/method message is :: #{message}"
end


def proc_message_printer(my_proc)
message = "Welcome to Proc Message Printer"
my_proc.() #Call my_proc
puts "But in this function/method message is :: #{message}"
end

def lambda_message_printer(my_lambda)
message = "Welcome to Lambda Message Printer"
my_lambda.call #Call my_lambda
puts "But in this function/method message is :: #{message}"
end
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Closures
You are viewing a single comment's thread. Return to all comments →
def block_message_printer message = "Welcome to Block Message Printer" if block_given? yield end puts "But in this function/method message is :: #{message}" end 

def proc_message_printer(my_proc) message = "Welcome to Proc Message Printer" my_proc.() #Call my_proc puts "But in this function/method message is :: #{message}" end 
def lambda_message_printer(my_lambda) message = "Welcome to Lambda Message Printer" my_lambda.call #Call my_lambda puts "But in this function/method message is :: #{message}" end