Class: Ori::LazyHash

Inherits:
LazyEnumerable show all
Defined in:
lib/ori/lazy.rb

Constant Summary collapse

INIT =
proc { {} }

Instance Method Summary collapse

Methods inherited from LazyEnumerable

#any?, #delete_if, #each, #empty?

Methods inherited from Lazy

#initialized?, #internal

Constructor Details

#initializeLazyHash

Returns a new instance of LazyHash.



82
83
84
# File 'lib/ori/lazy.rb', line 82

def initialize
  super(INIT)
end

Instance Method Details

#[](key) ⇒ Object



86
87
88
# File 'lib/ori/lazy.rb', line 86

def [](key)
  internal[key] if initialized?
end

#[]=(key, value) ⇒ Object



90
91
92
# File 'lib/ori/lazy.rb', line 90

def []=(key, value)
  internal[key] = value
end

#delete(key) ⇒ Object



94
95
96
# File 'lib/ori/lazy.rb', line 94

def delete(key)
  internal.delete(key) if initialized?
end

#fetch(index, default = nil) ⇒ Object



104
105
106
# File 'lib/ori/lazy.rb', line 104

def fetch(index, default = nil)
  internal[index] || default
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
101
102
# File 'lib/ori/lazy.rb', line 98

def key?(key)
  return false unless initialized?

  internal.key?(key)
end

#keysObject



114
115
116
117
118
# File 'lib/ori/lazy.rb', line 114

def keys
  return [] unless initialized?

  internal.keys
end

#none?Boolean

Returns:

  • (Boolean)


126
127
128
129
130
# File 'lib/ori/lazy.rb', line 126

def none?
  return true unless initialized?

  internal.none?
end

#reject(&block) ⇒ Object



108
109
110
111
112
# File 'lib/ori/lazy.rb', line 108

def reject(&block)
  return self unless initialized?

  internal.reject(&block)
end

#valuesObject



120
121
122
123
124
# File 'lib/ori/lazy.rb', line 120

def values
  return [] unless initialized?

  internal.values
end