File: return_values.rb

package info (click to toggle)
ruby-mocha 3.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,652 kB
  • sloc: ruby: 12,324; javascript: 499; makefile: 14
file content (29 lines) | stat: -rw-r--r-- 564 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

require 'mocha/single_return_value'

module Mocha
  class ReturnValues
    def self.build(*values)
      new(*values.map { |value| SingleReturnValue.new(value) })
    end

    attr_accessor :values

    def initialize(*values)
      @values = values
    end

    def next(invocation)
      case @values.length
      when 0 then nil
      when 1 then @values.first.evaluate(invocation)
      else @values.shift.evaluate(invocation)
      end
    end

    def +(other)
      self.class.new(*(@values + other.values))
    end
  end
end