public
Created

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# Sometimes I wish Array#map would take an argument for the index
# I usually think about it when I'm working with a CSV file
 
class Array
def map(arg=nil, &block)
if arg && block_given?
self.map(arg).map(&block)
elsif arg
self.map {|x| x[arg]}
else
super()
end
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.