Class: Subroutine::Outputs::LazyExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/subroutine/outputs.rb

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ LazyExecutor

Returns a new instance of LazyExecutor.



14
15
16
17
# File 'lib/subroutine/outputs.rb', line 14

def initialize(value)
  @value_block = value
  @executed = false
end

Instance Method Details

#executed?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/subroutine/outputs.rb', line 26

def executed?
  @executed
end

#valueObject



19
20
21
22
23
24
# File 'lib/subroutine/outputs.rb', line 19

def value
  return @value if @executed
  @value = @value_block.respond_to?(:call) ? @value_block.call : @value
  @executed = true
  @value
end