Created
March 4, 2014 18:39
-
-
Save amclain/9352771 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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