Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Instance Method Summary collapse

Instance Method Details

#deep_merge(*args) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'ext/sin_deep_merge/sin_deep_merge.c', line 68

static VALUE hash_deep_merge(int argc, VALUE* argv, VALUE self) {
  VALUE other;
  rb_scan_args(argc, argv, "1", &other);
  if (!RB_TYPE_P(other, T_HASH)) {
    other = rb_funcall(other, id_to_hash, 0);
    Check_Type(other, T_HASH);
  }
  VALUE block = Qnil;
  if (rb_block_given_p()) {
    block = rb_block_proc();
  }

  VALUE duplicated = rb_obj_dup(self);
  deep_merge_hashes(duplicated, other, block, 0);

  return duplicated;
}

#deep_merge!(*args) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'ext/sin_deep_merge/sin_deep_merge.c', line 50

static VALUE hash_deep_merge_bang(int argc, VALUE* argv, VALUE self) {
  VALUE other;
  rb_scan_args(argc, argv, "1", &other);
  rb_check_frozen(self);
  if (!RB_TYPE_P(other, T_HASH)) {
    other = rb_funcall(other, id_to_hash, 0);
    Check_Type(other, T_HASH);
  }
  VALUE block = Qnil;
  if (rb_block_given_p()) {
    block = rb_block_proc();
  }

  deep_merge_hashes(self, other, block, 1);

  return self;
}