Class: Plugs::Lazy

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Lazy

Returns a new instance of Lazy.



9
10
11
# File 'lib/lazy.rb', line 9

def initialize(&block)
  @proc = block
end

Class Method Details

.unwrap(value) ⇒ Object



5
6
7
# File 'lib/lazy.rb', line 5

def self.unwrap(value)
  value.is_a?(self) ? value.call : value
end

Instance Method Details

#callObject



13
14
15
16
17
# File 'lib/lazy.rb', line 13

def call
  return @call if defined?(@call)

  @call = @proc.call
end