class Simple::Lazy

Constants

VERSION

Attributes

value[R]

Public Class Methods

new(value, &block) click to toggle source
# File lib/simple/lazy.rb, line 7
def initialize(value, &block)
  @block = block
  @value = value
  @cached = nil
  @is_cached = false
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/simple/lazy.rb, line 22
def <=>(other)
  other.is_a?(Simple::Lazy) ? value <=> other.value : value <=> other
end
cached() click to toggle source
# File lib/simple/lazy.rb, line 38
def cached
  unless @is_cached
    @cached = @block.call(value)
    @is_cached = true
  end

  @cached
end
cached?() click to toggle source
# File lib/simple/lazy.rb, line 47
def cached?
  @is_cached
end
eql?(other) click to toggle source
# File lib/simple/lazy.rb, line 18
def eql?(other)
  other.is_a?(Simple::Lazy) ? value == other.value : value == other
end
hash() click to toggle source
# File lib/simple/lazy.rb, line 14
def hash
  value.hash
end
inspect() click to toggle source
# File lib/simple/lazy.rb, line 55
def inspect
  "#<Simple::Lazy @value=#{@value.inspect} cached?=#{cached?.inspect}>"
end
method_missing(method, *args, &block) click to toggle source
# File lib/simple/lazy.rb, line 26
def method_missing(method, *args, &block)
  cached.public_send(method, *args, &block)
end
methods() click to toggle source
# File lib/simple/lazy.rb, line 34
def methods
  methods + cached.methods
end
respond_to_missing?(method, include_private = false) click to toggle source
Calls superclass method
# File lib/simple/lazy.rb, line 30
def respond_to_missing?(method, include_private = false)
  cached.respond_to?(method) || super
end
to_s() click to toggle source
# File lib/simple/lazy.rb, line 51
def to_s
  cached.to_s
end