summaryrefslogtreecommitdiff
path: root/ext/digest/digest.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-09-13 23:32:12 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-09-13 23:32:12 +0000
commitbe02cb10f85b313e6c66469d5818115c8b049d8c (patch)
tree7facb09f04809c84a747b784018ad138494703a2 /ext/digest/digest.c
parent9bcbcb054a0c7d716026b3c7422096eb56b0f031 (diff)
* ext/digest/digest.c (rb_digest_base_inspect): new method.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10926 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/digest/digest.c')
-rw-r--r--ext/digest/digest.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/ext/digest/digest.c b/ext/digest/digest.c
index 9d3492a..a2e0d55 100644
--- a/ext/digest/digest.c
+++ b/ext/digest/digest.c
@@ -192,6 +192,27 @@ rb_digest_base_hexdigest(VALUE self)
}
static VALUE
+rb_digest_base_inspect(VALUE self)
+{
+ algo_t *algo;
+ VALUE str;
+ char *cname;
+
+ algo = get_digest_base_metadata(rb_obj_class(self));
+
+ cname = rb_obj_classname(self);
+
+ /* #<Digest::Alg: xxxxx...xxxx> */
+ str = rb_str_buf_new(2 + strlen(cname) + 2 + algo->digest_len * 2 + 1);
+ rb_str_buf_cat2(str, "#<");
+ rb_str_buf_cat2(str, cname);
+ rb_str_buf_cat2(str, ": ");
+ rb_str_buf_append(str, rb_digest_base_hexdigest(self));
+ rb_str_buf_cat2(str, ">");
+ return str;
+}
+
+static VALUE
rb_digest_base_equal(VALUE self, VALUE other)
{
algo_t *algo;
@@ -261,6 +282,7 @@ Init_digest(void)
rb_define_method(cDigest_Base, "digest", rb_digest_base_digest, 0);
rb_define_method(cDigest_Base, "hexdigest", rb_digest_base_hexdigest, 0);
rb_define_method(cDigest_Base, "to_s", rb_digest_base_hexdigest, 0);
+ rb_define_method(cDigest_Base, "inspect", rb_digest_base_inspect, 0);
rb_define_method(cDigest_Base, "==", rb_digest_base_equal, 1);
id_metadata = rb_intern("metadata");