From d314a7dd8540293dae14e1e2cfd2f80ca143a56e Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 6 Sep 2006 16:59:10 +0000 Subject: [PATCH] * string.c (sym_equal): override. check equivalence. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ string.c | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/ChangeLog b/ChangeLog index 517335eb99..e62f4a41e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Thu Sep 7 01:54:22 2006 Yukihiro Matsumoto + + * string.c (sym_equal): override. check equivalence. + Wed Sep 6 13:25:04 2006 Yukihiro Matsumoto * parse.y (symbols_i): need to initialize early-created symbols. diff --git a/string.c b/string.c index ce33f9541c..3935eb426e 100644 --- a/string.c +++ b/string.c @@ -4422,6 +4422,22 @@ rb_sym_s_intern(VALUE s) return rb_intern2(RSTRING_PTR(s), RSTRING_LEN(s)); } +/* + * call-seq: + * sym == obj => true or false + * + * Equality---If sym and obj are exactly the same + * symbol, returns true. Otherwise, returns + * false. + */ + +static VALUE +sym_equal(VALUE sym1, VALUE sym2) +{ + if (sym1 == sym2) return Qtrue; + return Qfalse; +} + /* * call-seq: * sym.to_i => fixnum @@ -4703,6 +4719,7 @@ Init_String(void) rb_define_singleton_method(rb_cSymbol, "all_symbols", rb_sym_all_symbols, 0); /* in parse.y */ rb_define_singleton_method(rb_cSymbol, "intern", rb_sym_s_intern, 1); + rb_define_method(rb_cSymbol, "==", sym_equal, 1); rb_define_method(rb_cSymbol, "to_i", sym_to_i, 0); rb_define_method(rb_cSymbol, "inspect", sym_inspect, 0); rb_define_method(rb_cSymbol, "to_s", sym_to_s, 0);