Method: Digest::Instance#==

Defined in:
digest.c

#==(another_digest_obj) ⇒ Boolean #==(string) ⇒ Boolean

If a string is given, checks whether it is equal to the hex-encoded hash value of the digest object. If another digest instance is given, checks whether they have the same hash value. Otherwise returns false.

Overloads:

  • #==(another_digest_obj) ⇒ Boolean

    Returns:

    • (Boolean)
  • #==(string) ⇒ Boolean

    Returns:

    • (Boolean)


367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'digest.c', line 367

static VALUE
rb_digest_instance_equal(VALUE self, VALUE other)
{
    VALUE str1, str2;

    if (rb_obj_is_kind_of(other, rb_mDigest_Instance) == Qtrue) {
        str1 = rb_digest_instance_digest(0, 0, self);
        str2 = rb_digest_instance_digest(0, 0, other);
    } else {
        str1 = rb_digest_instance_to_s(self);
        str2 = rb_check_string_type(other);
        if (NIL_P(str2)) return Qfalse;
    }

    /* never blindly assume that subclass methods return strings */
    StringValue(str1);
    StringValue(str2);

    if (RSTRING_LEN(str1) == RSTRING_LEN(str2) &&
	rb_str_cmp(str1, str2) == 0) {
	return Qtrue;
    }
    return Qfalse;
}