Created
June 19, 2012 08:09
-
-
Save vitaly/2952933 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 C | |
def initialize(x) | |
@x = x | |
end | |
def each(&block) | |
@x.times(&block) | |
end | |
include Enumerable | |
end | |
# example simplistic implementation for Enumerable | |
module Enumerable | |
def map(&block) | |
res = [] | |
each do |el| | |
res << block.call(el) | |
end | |
res | |
end | |
def select(&block) | |
res = [] | |
each do |el| | |
res << el if block.call(el) | |
end | |
end | |
def group_by(&block) | |
res = {} | |
each do |el| | |
key = block.call(el) | |
res[key] ||= [] | |
res[key] << el | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment