Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/monkeypatch.rb,
lib/monkeypatch.rb
Instance Method Summary collapse
- #compact ⇒ Object
-
#deep_merge(second) ⇒ Object
rubocop:disable Style/CaseEquality rubocop:disable Lint/UnusedBlockArgument.
- #fnjoin(separator = "") ⇒ Object
- #fnselect(index = 0) ⇒ Object
- #fnsplit(separator = "") ⇒ Object
- #fnsub(variable_map = nil) ⇒ Object
-
#recursive_compact ⇒ Object
rubocop:enable Style/CaseEquality rubocop:enable Lint/UnusedBlockArgument.
Instance Method Details
#compact ⇒ Object
221 222 223 |
# File 'lib/monkeypatch.rb', line 221 def compact delete_if { |_k, v| v.nil? } end |
#deep_merge(second) ⇒ Object
rubocop:disable Style/CaseEquality rubocop:disable Lint/UnusedBlockArgument
207 208 209 210 |
# File 'lib/monkeypatch.rb', line 207 def deep_merge(second) merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : Array === v1 && Array === v2 ? v1 | v2 : [:undefined, nil, :nil].include?(v2) ? v1 : v2 } self.merge(second.to_h, &merger) end |
#fnjoin(separator = "") ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/monkeypatch.rb', line 40 def fnjoin(separator = "") { "Fn::Join": [ separator, self ] } end |
#fnselect(index = 0) ⇒ Object
225 226 227 228 229 230 231 232 |
# File 'lib/monkeypatch.rb', line 225 def fnselect(index = 0) { "Fn::Select": [ index, self ] } end |
#fnsplit(separator = "") ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/monkeypatch.rb', line 49 def fnsplit(separator = "") { "Fn::Split": [ separator, self ] } end |
#fnsub(variable_map = nil) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/monkeypatch.rb', line 234 def fnsub(variable_map = nil) unless variable_map return { "Fn::Sub": self } end { "Fn::Sub": [ self, variable_map ] } end |
#recursive_compact ⇒ Object
rubocop:enable Style/CaseEquality rubocop:enable Lint/UnusedBlockArgument
214 215 216 217 218 219 |
# File 'lib/monkeypatch.rb', line 214 def recursive_compact delete_if do |k, v| next if v == false || k =~ /Fn\:/ (v.respond_to?(:empty?) ? v.empty? : !v) || v.instance_of?(Hash) && v.recursive_compact.empty? end end |