From: Dan Schmidt Date: 2001-05-24T01:41:24+09:00 Subject: [ruby-talk:15600] multisend? I frequently find myself wanting to take, say, the five matches returned by a regular expression, and call to_i (or hex, or whatever) on some of them, e.g.; str =~ /^(\d+) (\w+) (\d+) (\d+) (\w+)/ id, name, height, weight, potato = $~[1..5] id = id.to_i height = height.to_i weight = weight.to_i which always feels kind of clunky (maybe partially because you don't have to perform these conversions in perl). I got sick of all that typing and now instead use the following code: str =~ /^(\d+) (\w+) (\d+) (\d+) (\w+)/ id, name, height, weight, potato = $~[1..5].multisend (:to_i, nil, :to_i, :to_i, nil) where multisend is defined thus: # naive implementation class Enumerable def multisend (*arr) i = -1 self.map { |x| i += 1 arr[i] ? x.__send__ (arr[i]) : x } end end Am I reimplementing a wheel that already exists? Can this be implemented (or designed) better? Is this a useful enough concept to consider putting something like it in the core library? Is it a monstrosity of codesize optimization, creating ugly and unreadable code? -- http://www.dfan.org