Skip to content

Instantly share code, notes, and snippets.

@richardc
Created February 10, 2015 14:57
Show Gist options
  • Save richardc/9847165d128ff2d126d8 to your computer and use it in GitHub Desktop.
Save richardc/9847165d128ff2d126d8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def runblock(foo)
# fake data
data = [1, 2, 3]
if block_given?
data.each { |v| yield(v) }
end
data
end
def printer(data)
# like printrpc, but simpler
puts "data has #{data.size} elements"
end
runblock('foo')
printer runblock('foo')
runblock('foo') do |value|
puts value
end
printer runblock('foo') do |value|
puts value
end
$ ruby call_block.print.rb
data has 3 elements
1
2
3
data has 3 elements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment