Class: Tengu::Double

Inherits:
Object
  • Object
show all
Defined in:
lib/tengu/double.rb

Instance Method Summary collapse

Constructor Details

#initialize(identifier = nil, methods = {}) ⇒ Double

Returns a new instance of Double.



3
4
5
6
7
8
# File 'lib/tengu/double.rb', line 3

def initialize(identifier = nil, methods = {})
  @identifier = identifier
  methods.each do |message, value|
    define_singleton_method message, -> (*args) { _tengu_received[message] << args; value }
  end
end

Instance Method Details

#_tengu_receivedObject



10
11
12
# File 'lib/tengu/double.rb', line 10

def _tengu_received
  @_tengu_received ||= Hash.new { |hash, key| hash[key] = [] }
end

#_tengu_received?(message, args = []) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
# File 'lib/tengu/double.rb', line 14

def _tengu_received?(message, args = [])
  if args.length > 0
    _tengu_received[message] && _tengu_received[message].include?(args)
  else
    _tengu_received.keys.include?(message)
  end
end