Class: LazyIdentity
- Inherits:
-
Object
- Object
- LazyIdentity
- Defined in:
- lib/rumonade/lazy_identity.rb
Overview
Instance Attribute Summary collapse
-
#lazy ⇒ Object
readonly
Returns the value of attribute lazy.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #bind(lam = nil, &blk) ⇒ Object
- #force ⇒ Object
-
#initialize(lam = nil, &blk) ⇒ LazyIdentity
constructor
:nodoc:.
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
#lazy ⇒ Object (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 |
#force ⇒ Object
11 12 13 |
# File 'lib/rumonade/lazy_identity.rb', line 11 def force @lazy[] end |