Skip to content

Instantly share code, notes, and snippets.

@krokrob
Created July 11, 2019 08:38
Show Gist options
  • Save krokrob/289c6dc471d5c6ea6ba1b55ec97a336b to your computer and use it in GitHub Desktop.
Save krokrob/289c6dc471d5c6ea6ba1b55ec97a336b to your computer and use it in GitHub Desktop.
def timer
start_time = Time.now
puts 'starting a long algorithm....'
yield
puts 'process done!'
end_time = Time.now
return end_time - start_time
end
# timer do
# sleep 2
# end
# puts time2
# time1 = timer do
# sleep 1
# end
# puts time1
puts '------------'
def greet(first_name, last_name)
full_name = "#{first_name.capitalize} #{last_name.upcase}"
greeting = yield(full_name)
return greeting
end
hi = greet('john', 'lennon') do |full_name|
"Hello, #{full_name}"
end
puts hi
bonjour = greet('john', 'lennon') do |full_name|
"Bonjour, #{full_name}"
end
puts bonjour
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment