Created
June 16, 2012 01:53
-
-
Save dkan/2939592 to your computer and use it in GitHub Desktop.
blocs and procs
This file contains 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
friends = ["Sally", "Mary", "Joe"] | |
love = [] | |
friends.each do |friend| | |
love << "I love " + friend + "." | |
end | |
puts love | |
class Array | |
def new_collect | |
result = [] | |
self.each do |friend| | |
result << yield(friend) | |
end | |
result | |
end | |
class Array | |
def new_count | |
result = 0 | |
self.each do |number| | |
if yield(number) | |
result += 1 | |
end | |
end | |
result | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment