Skip to content

Instantly share code, notes, and snippets.

@a13e
Created February 15, 2015 05:19
Show Gist options
  • Save a13e/9ad1d8cf1dbc0c7725d3 to your computer and use it in GitHub Desktop.
Save a13e/9ad1d8cf1dbc0c7725d3 to your computer and use it in GitHub Desktop.
Mix-in Enumerable Module
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