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.



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

def initialize
  super(INIT)
end

Instance Method Details

#[](key) ⇒ Object



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

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

#[]=(key, value) ⇒ Object



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

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

#delete(key) ⇒ Object



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

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

#fetch(index, default = nil) ⇒ Object



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

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


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

def key?(key)
  return false unless initialized?

  internal.key?(key)
end

#keysObject



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

def keys
  return [] unless initialized?

  internal.keys
end

#none?Boolean

Returns:

  • (Boolean)


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

def none?
  return true unless initialized?

  internal.none?
end

#reject(&block) ⇒ Object



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

def reject(&block)
  return self unless initialized?

  internal.reject(&block)
end

#valuesObject



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

def values
  return [] unless initialized?

  internal.values
end