Created
December 9, 2009 20:48
-
-
Save therealadam/252797 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def map_e(elz, &block) | |
results = [] | |
if length > 0 | |
each do |o| | |
block.call(o) | |
end | |
else | |
elz.call | |
end | |
end | |
end | |
# Ruby 1.9-style lambdas make this read a little better | |
puts %w{dog cat zebra}.map_e(-> { 'No animals!' }) { |o| o.upcase } | |
puts [].map_e(->{ 'No animals' }) { |o| o.upcase } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment