Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/sin_deep_merge.rb

Instance Method Summary collapse

Instance Method Details

#deep_merge(other) ⇒ Object



97
98
99
100
101
102
103
# File 'ext/sin_deep_merge/sin_deep_merge.c', line 97

static VALUE hash_deep_merge(VALUE self, VALUE other) {
  if (!plain_hash_p(self)) return deep_merge_fallback(self, other, "deep_merge");

  other = rb_convert_type(other, T_HASH, "Hash", "to_hash");

  return deep_merge_hashes(deep_merge_hash_dup(self), other, rb_block_given_p());
}

#deep_merge!(other) ⇒ Object



87
88
89
90
91
92
93
94
95
# File 'ext/sin_deep_merge/sin_deep_merge.c', line 87

static VALUE hash_deep_merge_bang(VALUE self, VALUE other) {
  /* Hand over before converting other: a subclass may treat a Hash and a to_hash convertible differently, as merge! is free to. */
  if (!plain_hash_p(self)) return deep_merge_fallback(self, other, "deep_merge!");

  rb_check_frozen(self);
  other = rb_convert_type(other, T_HASH, "Hash", "to_hash");

  return deep_merge_hashes(self, other, rb_block_given_p());
}