Skip to content

Instantly share code, notes, and snippets.

@amclain
Created March 4, 2014 18:39
Show Gist options
  • Save amclain/9352771 to your computer and use it in GitHub Desktop.
Save amclain/9352771 to your computer and use it in GitHub Desktop.
require 'pry'
class Read
def initialize value = 0
@value = value
end
def to_s
"#{@value}:Read"
end
end
class Write
def initialize value = 0
@value = value
end
def to_s
"#{@value}:Write"
end
end
i = [Read.new(1), Read.new(2), Write.new(3), Read.new(4), Write.new(5)]
def action items, read_proc, write_proc
items.each do |i|
read_proc.call i if i.is_a? Read
write_proc.call i if i.is_a? Write
end
end
r = Proc.new do |item|
puts "Reader proc: #{item}"
end
w = Proc.new do |item|
puts "Writer proc: #{item}"
end
action i, r, w
# binding.pry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment