Class: Pretentious::RecordedProc
- Inherits:
-
Proc
- Object
- Proc
- Pretentious::RecordedProc
- 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
-
#return_value ⇒ Object
readonly
Returns the value of attribute return_value.
-
#target_proc ⇒ Object
readonly
Returns the value of attribute target_proc.
Instance Method Summary collapse
- #call(*args, &block) ⇒ Object
- #given_block? ⇒ Boolean
-
#initialize(target_proc, is_given_block = false) ⇒ RecordedProc
constructor
A new instance of RecordedProc.
- #is_called? ⇒ Boolean
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_value ⇒ Object (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_proc ⇒ Object (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
14 15 16 |
# File 'lib/pretentious/recorded_proc.rb', line 14 def given_block? @given_block end |
#is_called? ⇒ Boolean
18 19 20 |
# File 'lib/pretentious/recorded_proc.rb', line 18 def is_called? @called end |