Class: RBS::UnitTest::WithAliases::WithEnum

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rbs/unit_test/with_aliases.rb

Instance Method Summary collapse

Constructor Details

#initialize(enum) ⇒ WithEnum

Returns a new instance of WithEnum.



11
# File 'lib/rbs/unit_test/with_aliases.rb', line 11

def initialize(enum) = @enum = enum

Instance Method Details

#and(*args, &block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rbs/unit_test/with_aliases.rb', line 27

def and(*args, &block)
  return WithEnum.new to_enum(__method__ || raise, *args) unless block

  each(&block)
  args.each do |arg|
    if WithEnum === arg # use `===` as `arg` might not have `.is_a?` on it
      arg.each(&block)
    else
      block.call(_ = arg)
    end
  end
end

#and_nil(&block) ⇒ Object



15
16
17
# File 'lib/rbs/unit_test/with_aliases.rb', line 15

def and_nil(&block)
  self.and(nil, &_ = block)
end

#but(*cases, &block) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/rbs/unit_test/with_aliases.rb', line 19

def but(*cases, &block)
  return WithEnum.new to_enum(__method__ || raise, *cases) unless block

  each do |arg|
    yield arg unless cases.any? { (_ = _1) === arg }
  end
end

#each(&block) ⇒ Object



13
# File 'lib/rbs/unit_test/with_aliases.rb', line 13

def each(&block) = @enum.each(&block)