Skip to content

Instantly share code, notes, and snippets.

@zimbatm
Created October 10, 2008 17:37
Show Gist options
  • Save zimbatm/16106 to your computer and use it in GitHub Desktop.
Save zimbatm/16106 to your computer and use it in GitHub Desktop.
Discovering my own code
module Kernel
# What is this ? I don't remember...
def [](*args, &block)
# FIXME: access control
send(*args, &block)
end
# Looks like "curry", method composition like in Ocaml
def defer(*args, &block)
DeferCall.new( block_given? ? block : method(args.shift), *args )
end
end
class DeferCall
def initialize(block, *args)
@block, @args = block, args
end
def call(*args)
@block.call(*(@args + args))
end
alias [] call
end
=begin usage example
d = defer(:puts, "Hello")
d.call("World")
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment