Skip to content

Commit

Permalink
Add missing Enumerable methods as not implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
meh committed Nov 15, 2013
1 parent bbb3551 commit 5303510
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions opal/core/enumerable.rb
Expand Up @@ -67,6 +67,10 @@ def any?(&block)
}
end

def chunk(state = undefined, &block)
raise NotImplementedError
end

def collect(&block)
return enum_for :collect unless block_given?

Expand All @@ -90,6 +94,10 @@ def collect(&block)
}
end

def collect_concat(&block)
raise NotImplementedError
end

def count(object = undefined, &block)
%x{
var result = 0;
Expand Down Expand Up @@ -282,6 +290,14 @@ def drop_while(&block)
}
end

def each_cons(n, &block)
raise NotImplementedError
end

def each_entry(&block)
raise NotImplementedError
end

def each_slice(n, &block)
n = Opal.coerce_to n, Integer, :to_int

Expand Down Expand Up @@ -511,6 +527,8 @@ def first(number = undefined)
result
end

alias flat_map collect_concat

def grep(pattern, &block)
%x{
var result = [];
Expand Down Expand Up @@ -658,7 +676,6 @@ def lazy
def enumerator_size
respond_to?(:size) ? size : nil
end

private :enumerator_size

alias map collect
Expand Down Expand Up @@ -833,6 +850,14 @@ def min_by(&block)
}
end

def minmax(&block)
raise NotImplementedError
end

def minmax_by(&block)
raise NotImplementedError
end

def none?(&block)
%x{
var result = true;
Expand Down Expand Up @@ -913,6 +938,18 @@ def one?(&block)
}
end

def partition(&block)
raise NotImplementedError
end

alias reduce inject

def reverse_each(&block)
raise NotImplementedError
end

alias select find_all

def slice_before(pattern = undefined, &block)
if `pattern === undefined && block === nil || arguments.length > 1`
raise ArgumentError, "wrong number of arguments (#{`arguments.length`} for 1)"
Expand Down Expand Up @@ -973,6 +1010,10 @@ def slice_before(pattern = undefined, &block)
}
end

def sort(&block)
raise NotImplementedError
end

def sort_by(&block)
return enum_for :sort_by unless block_given?

Expand All @@ -983,10 +1024,6 @@ def sort_by(&block)
}.sort { |a, b| a[0] <=> b[0] }.map { |arg| `arg[1]` }
end

alias select find_all

alias reduce inject

def take(num)
first(num)
end
Expand Down Expand Up @@ -1020,5 +1057,9 @@ def take_while(&block)
end

alias to_a entries

def zip(*lists, &block)
raise NotImplementedError
end
end

0 comments on commit 5303510

Please sign in to comment.