Example #1
0
static mrb_value
range_eql(mrb_state *mrb, mrb_value range)
{
  mrb_value obj;
  mrb_get_args(mrb, "o", &obj);

  if (mrb_obj_equal(mrb, range, obj))
    return mrb_true_value();
  if (!mrb_obj_is_kind_of(mrb, obj, mrb->range_class))
    return mrb_false_value();
  return mrb_exec_recursive_paired(mrb, recursive_eql, range, obj, &obj);
}
Example #2
0
/*
 * code-seq:
 *   struct.eql?(other)   -> true or false
 *
 * Two structures are equal if they are the same object, or if all their
 * fields are equal (using <code>eql?</code>).
 */
static mrb_value
mrb_struct_eql(mrb_state *mrb, mrb_value s)
{
  mrb_value s2;

  mrb_get_args(mrb, "o", &s2);
  if (mrb_obj_equal(mrb, s, s2)) return mrb_true_value();
  if (mrb_type(s2) != MRB_TT_STRUCT) return mrb_false_value();
  if (mrb_obj_class(mrb, s) != mrb_obj_class(mrb, s2)) return mrb_false_value();
  if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) {
    mrb_bug("inconsistent struct"); /* should never happen */
  }

  return mrb_exec_recursive_paired(mrb, recursive_eql, s, s2, (void*)0);
}
Example #3
0
File: hash.c Project: Zyxwvu/mruby
static mrb_value
hash_equal(mrb_state *mrb, mrb_value hash1, mrb_value hash2, int eql)
{
  if (mrb_obj_equal(mrb, hash1, hash2)) return mrb_true_value();
  if (mrb_type(hash2) != MRB_TT_HASH) {
      if (!mrb_respond_to(mrb, hash2, mrb_intern(mrb, "to_hash"))) {
          return mrb_false_value();
      }
      if (eql)
          return mrb_fixnum_value(mrb_eql(mrb, hash2, hash1));
      else
          return mrb_fixnum_value(mrb_equal(mrb, hash2, hash1));
  }
  if (RHASH_SIZE(hash1) != RHASH_SIZE(hash2)) return mrb_false_value();
  if (!RHASH(hash1)->ht || !RHASH(hash2)->ht) return mrb_true_value();

  return mrb_exec_recursive_paired(mrb, recursive_eql, hash1, hash2, (void*)0);
}