Skip to content

Instantly share code, notes, and snippets.

@usergenic
Created January 24, 2011 21:16
Show Gist options
  • Select an option

  • Save usergenic/793973 to your computer and use it in GitHub Desktop.

Select an option

Save usergenic/793973 to your computer and use it in GitHub Desktop.
module Enumerable
class Proxy
instance_methods.each do |method|
next if method.to_s =~ /\A__(id|send)__\Z/
undef_method(method)
end
def initialize(target, method=:map)
@target, @method = target, method
end
private
def method_missing(method, *args, &block)
@target.__send__(@method) do |item|
item.__send__(method, *args, &block)
end
end
end
def every(method=:map)
Proxy.new(self, method)
end
end
# >> [1,2,3].every.to_s
# => ['1','2','3']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment