Skip to content

Instantly share code, notes, and snippets.

@enil
Created July 4, 2013 17:04
Show Gist options
  • Save enil/5929140 to your computer and use it in GitHub Desktop.
Save enil/5929140 to your computer and use it in GitHub Desktop.
The way arrays are used as an variable argument list, *unless* the arity of a proc is 1 is a clusterfuck. I think this is a safe way to fix a proc so that sending an array to the proc always treats the array as an argument list. `BasicObject.instance_exec` doesn't seem to use `Proc.call`, it has to be dealt with separately.
class Proc
def unfuck!
class << self
def call(*params)
if arity == 1 && params.first.is_a?(Array)
super(params.first.first)
else
super
end
end
end
self
end
end
@enil
Copy link
Author

enil commented Jul 4, 2013

It doesn't seem like yield uses Proc.call either, to yield to an unfucked proc you have to do something like this:

def foo(params, &block)
  block.unfuck!
  block.call(params)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment