Skip to content

Instantly share code, notes, and snippets.

@lgranger
Created November 20, 2015 06:39
Show Gist options
  • Save lgranger/b681e2f5684a94e6ece5 to your computer and use it in GitHub Desktop.
Save lgranger/b681e2f5684a94e6ece5 to your computer and use it in GitHub Desktop.
## Proc Examples
# Penny Randomly Barks or Woofs
proc_rand = Proc.new do
if rand(2) == 0
true
else
false
end
end
def penny_speaks proc1
if proc1.call == true
puts "Woof!"
else
puts "Bark! Bark!"
end
end
# Penny Barks or Growls at people
proc_peeps = Proc.new do
if peeps == "friends"
true
elsif peeps == "family"
true
else
false
end
end
def penny_speaks(peeps, &proc1)
if proc1.call == true
puts "Woof! Bark! Bark! *happy wag*"
else
puts "GRRRRRRR!! *defence stance*"
end
end
penny_speaks(peeps,
## Grandfather Clock Exercise
proc_hour = Proc.new do
if Time.now.hour <13
Time.now.hour
else
Time.now.hour - 12
end
end
def gclock proc_h
t = proc_h.call
t.times{puts "Bing-Bong!"}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment