mruby-set/set.rb (do_with_enum): prefix _ to internal method.

This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-10-21 14:50:22 +09:00
parent 59162ceb4e
commit d5e13a7f2a
+13 -13
View File
@@ -1,6 +1,15 @@
class Set
include Enumerable
# internal method
def _do_with_enum(enum, &block)
if enum.respond_to?(:each)
enum.each(&block)
else
raise ArgumentError, "value must be enumerable"
end
end
def self.[](*ary)
new(ary)
end
@@ -11,21 +20,12 @@ class Set
enum.nil? and return
if block_given?
do_with_enum(enum) { |o| add(block.call(o)) }
_do_with_enum(enum) { |o| add(block.call(o)) }
else
merge(enum)
end
end
def do_with_enum(enum, &block)
if enum.respond_to?(:each)
enum.each(&block)
else
raise ArgumentError, "value must be enumerable"
end
end
private :do_with_enum
def initialize_copy(orig)
super
@hash = orig.instance_variable_get(:@hash).dup
@@ -231,14 +231,14 @@ class Set
if enum.instance_of?(self.class)
@hash.merge!(enum.instance_variable_get(:@hash))
else
do_with_enum(enum) { |o| add(o) }
_do_with_enum(enum) { |o| add(o) }
end
self
end
def subtract(enum)
do_with_enum(enum) { |o| delete(o) }
_do_with_enum(enum) { |o| delete(o) }
self
end
@@ -255,7 +255,7 @@ class Set
def &(enum)
n = Set.new
do_with_enum(enum) { |o| n.add(o) if include?(o) }
_do_with_enum(enum) { |o| n.add(o) if include?(o) }
n
end
alias intersection &