avoid subclassing Array not to inherit too much methods

parent c304887b
...@@ -170,19 +170,28 @@ module MRuby ...@@ -170,19 +170,28 @@ module MRuby
end # Specification end # Specification
class List < Array class List
include Enumerable
def initialize
@ary = []
end
def each(&b)
@ary.each(&b)
end
def <<(gem) def <<(gem)
fail ArgumentError.new("Don't find directory for this GEM") unless gem.respond_to? :dir fail ArgumentError.new("Don't find directory for this GEM") unless gem.respond_to? :dir
unless include?(gem) unless @ary.detect {|g| g.dir == gem.dir }
super(gem) @ary << gem
else else
# GEM was already added to this list # GEM was already added to this list
end end
end end
# we assume that a gem with the same directory is equal def empty?
def include?(gem) @ary.empty?
detect {|g| g.dir == gem.dir }
end end
end # List end # List
end # Gem end # Gem
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment