module ATD::Refinements
Public Instance Methods
class_instance_variables()
click to toggle source
Returns the instance variables of a class
# File lib/atd/builtin_class_modifications.rb, line 31 def class_instance_variables instance_variables.map { |var| [var, instance_variable_get(var)] }.to_h end
deep_merge(second)
click to toggle source
Not only merges two hashes, but also merges the hashes that may be nested in.
For example:
{a: {b: "c"}}
Is a nested hash
# File lib/atd/builtin_class_modifications.rb, line 9 def deep_merge(second) merger = proc do |_, v1, v2| if v1.is_a?(Hash) && v2.is_a?(Hash) then v1.merge(v2, &merger) elsif v1.is_a?(Array) && v2.is_a?(Array) then v1 | v2 elsif [:undefined, nil, :nil].include?(v2) then v1 else v2 end end merge(second.to_h, &merger) end
include_in_key?(search)
click to toggle source
# File lib/atd/builtin_class_modifications.rb, line 20 def include_in_key?(search) each do |key, val| return val if key.is_a?(Array) && key.include?(search) end end
where(criteria)
click to toggle source
# File lib/atd/builtin_class_modifications.rb, line 37 def where(criteria) select do |element| criteria.all? do |criterion, expected_value| Array(element.public_send(criterion)).include?(expected_value) end end end