Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Better than methodphitamine? (See related posts)

Original discussion here: http://jicksta.com/articles/2007/08/04/the-methodphitamine

I think this one is prettier (but maybe not as sophisticated):

module Enumerable
  def method_missing(sym, *args)
    if (sym.to_s =~ /^(.+)_with$/) && (msg = args.shift)
      send($1.to_sym) do |x|
        x.send(msg, *args)
      end
    end
  end
end

[1, 2, 3].map_with :to_s


You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts