D
Daniel Schierbeck
Browsing through the list of method, I couldn't find a method that did
what I wanted it to, although Enumerable#every is close.
class Array
def send_to_each(symbol, *args)
collect{|obj| obj.send(symbol, *args)}
end
end
arr = ["cat", "dog", "monkey"]
arr.send_to_eachupcase) #=> ["CAT", "DOG", "MONKEY"]
arr #=> ["cat", "dog", "monkey"]
arr.send_to_eachupcase!) #=> ["CAT", "DOG", "MONKEY"]
arr #=> ["CAT", "DOG", "MONKEY"]
I'm only putting it in Array, and not Enumerable, because I'm not sure
it will be of use to hashes etc.
Take it or leave it
Cheers,
Daniel
what I wanted it to, although Enumerable#every is close.
class Array
def send_to_each(symbol, *args)
collect{|obj| obj.send(symbol, *args)}
end
end
arr = ["cat", "dog", "monkey"]
arr.send_to_eachupcase) #=> ["CAT", "DOG", "MONKEY"]
arr #=> ["cat", "dog", "monkey"]
arr.send_to_eachupcase!) #=> ["CAT", "DOG", "MONKEY"]
arr #=> ["CAT", "DOG", "MONKEY"]
I'm only putting it in Array, and not Enumerable, because I'm not sure
it will be of use to hashes etc.
Take it or leave it
Cheers,
Daniel