Class: Compact::Invocation

Inherits:
Object
  • Object
show all
Defined in:
lib/compact/invocation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method:, args:, returns:) ⇒ Invocation

Returns a new instance of Invocation.



4
5
6
7
8
# File 'lib/compact/invocation.rb', line 4

def initialize( method:, args:,  returns:)
  @method = method
  @args = args
  @returns = returns
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



3
4
5
# File 'lib/compact/invocation.rb', line 3

def args
  @args
end

#methodObject (readonly)

Returns the value of attribute method.



3
4
5
# File 'lib/compact/invocation.rb', line 3

def method
  @method
end

#returnsObject (readonly)

Returns the value of attribute returns.



3
4
5
# File 'lib/compact/invocation.rb', line 3

def returns
  @returns
end

Instance Method Details

#==(other_invocation) ⇒ Object



10
11
12
13
# File 'lib/compact/invocation.rb', line 10

def == other_invocation
  same_returns = returns == other_invocation.returns
  matches_call(other_invocation) && same_returns
end

#describeObject



29
30
31
32
33
34
35
# File 'lib/compact/invocation.rb', line 29

def describe
  <<~DESCRIPTION
  method: #{method}
  invoke with: #{args.inspect}
  returns: #{returns}
  DESCRIPTION
end

#eql?(other_invocation) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/compact/invocation.rb', line 15

def eql? other_invocation
  self.== other_invocation
end

#hashObject



19
20
21
# File 'lib/compact/invocation.rb', line 19

def hash
  describe.hash
end

#matches_call(other_invocation) ⇒ Object



23
24
25
26
27
# File 'lib/compact/invocation.rb', line 23

def matches_call(other_invocation)
  same_args = args == other_invocation.args
  same_method = method == other_invocation.method
  same_args && same_method
end