Created
February 15, 2015 05:19
-
-
Save a13e/9ad1d8cf1dbc0c7725d3 to your computer and use it in GitHub Desktop.
Mix-in Enumerable Module
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
class FriendList | |
include Enumerable | |
def initialize(*friends) | |
@friends = friends | |
end | |
def each | |
for v in @friends | |
yield v | |
end | |
end | |
end | |
friend_list = FriendList.new('Alice', 'Bob', 'Charlie') | |
puts friend_list.count #=> 3 | |
puts friend_list.map { |v| v.upcase } | |
puts friend_list.find { |v| /b/ === v } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment