Class: Pretentious::RecordedProc

Inherits:
Proc
  • Object
show all
Defined in:
lib/pretentious/recorded_proc.rb

Overview

Sublass of Proc that records whatever was passed to it and whatever it returns

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_proc, is_given_block = false) ⇒ RecordedProc

Returns a new instance of RecordedProc.



6
7
8
9
10
11
12
# File 'lib/pretentious/recorded_proc.rb', line 6

def initialize(target_proc, is_given_block = false)
  @target_proc = target_proc
  @return_value = []
  @args = []
  @given_block = is_given_block
  @called = false
end

Instance Attribute Details

#return_valueObject (readonly)

Returns the value of attribute return_value.



4
5
6
# File 'lib/pretentious/recorded_proc.rb', line 4

def return_value
  @return_value
end

#target_procObject (readonly)

Returns the value of attribute target_proc.



4
5
6
# File 'lib/pretentious/recorded_proc.rb', line 4

def target_proc
  @target_proc
end

Instance Method Details

#call(*args, &block) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/pretentious/recorded_proc.rb', line 22

def call(*args, &block)
  @called = true
  @args << args
  return_value = @target_proc.call(*args, &block)

  @return_value << return_value unless @return_value.include? return_value
  return_value
end

#given_block?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/pretentious/recorded_proc.rb', line 14

def given_block?
  @given_block
end

#is_called?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/pretentious/recorded_proc.rb', line 18

def is_called?
  @called
end