Class: LazyIdentity

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

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lam = nil, &blk) ⇒ LazyIdentity

:nodoc:



3
4
5
6
7
# File 'lib/rumonade/lazy_identity.rb', line 3

def initialize(lam = nil, &blk)
  @lazy = lam || blk
  @lazy.is_a?(Proc) || raise(ArgumentError, "not a Proc")
  @lazy.arity.zero? || raise(ArgumentError, "arity must be 0, was #{@lazy.arity}")
end

Instance Attribute Details

#lazyObject (readonly)

Returns the value of attribute lazy.



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

def lazy
  @lazy
end

Class Method Details

.unit(lam = nil, &blk) ⇒ Object



15
16
17
# File 'lib/rumonade/lazy_identity.rb', line 15

def self.unit(lam = nil, &blk)
  LazyIdentity.new(lam || blk)
end

Instance Method Details

#==(other) ⇒ Object



24
25
26
# File 'lib/rumonade/lazy_identity.rb', line 24

def ==(other)
  other.is_a?(LazyIdentity) && other.force == force
end

#bind(lam = nil, &blk) ⇒ Object



19
20
21
22
# File 'lib/rumonade/lazy_identity.rb', line 19

def bind(lam = nil, &blk)
  f = lam || blk
  f[@lazy]
end

#forceObject



11
12
13
# File 'lib/rumonade/lazy_identity.rb', line 11

def force
  @lazy[]
end