Skip to content

Instantly share code, notes, and snippets.

@lukeledet
Created January 27, 2012 00:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lukeledet/1686123 to your computer and use it in GitHub Desktop.
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment