From: "David A. Black" Date: 2005-10-28T22:45:40+09:00 Subject: Re: Cleaner syntax for .map (is there already a way, or ruby2 idea?) Hi -- On Fri, 28 Oct 2005, Daniel Schierbeck wrote: > Daniel Schierbeck wrote: >> David A. Black wrote: >> >>> I know that people.every could return >>> some kind of generator or enumerator, which could then be fed >>> "email_addr" symbolically... >> >> >> >> module Enumerable >> def every >> enum, obj = self, Object.new >> obj.define_method :method_missing do |name, *args| >> enum.map { |element| element.send(name, *args) } If you must do this, you'd probably want each rather than map there. >> end >> return obj >> end >> end >> >> ary = ["john", "sylvia", "sarah"] >> ary.every.capitalize! >> >> puts ary.join(", ") -> John, Sylvia, Sarah >> >> >> >> Cheers, >> Daniel > > By the way, you need the Object#define_method if you want it to work: I definitely *don't* want it to work :-) I dislike using dot syntax for non-dot semantics. I've never liked things like: hash.where.the.key.equals(10) even though they can usually be made to work. I continue to struggle to understand what people find so horrible about ary.each {|item| .... }, ary.map {|item| ... }, and so forth. I'll have some more coffee and maybe I'll start to see the light.... David -- David A. Black dblack@wobblini.net