ruby-changes:47135
From: ktsj <ko1@a...>
Date: Sun, 2 Jul 2017 19:38:47 +0900 (JST)
Subject: [ruby-changes:47135] ktsj:r59250 (trunk): Symbol#== should be able to be redefined
ktsj 2017-07-02 19:38:38 +0900 (Sun, 02 Jul 2017) New Revision: 59250 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59250 Log: Symbol#== should be able to be redefined * vm.c (vm_init_redefined_flag): set redefinition flag for Symbol#==. The bug was introduced in r58895. * test/ruby/test_symbol.rb: test for above. Modified files: trunk/test/ruby/test_symbol.rb trunk/vm.c Index: vm.c =================================================================== --- vm.c (revision 59249) +++ vm.c (revision 59250) @@ -1576,7 +1576,7 @@ vm_init_redefined_flag(void) https://github.com/ruby/ruby/blob/trunk/vm.c#L1576 OP(MULT, MULT), (C(Integer), C(Float)); OP(DIV, DIV), (C(Integer), C(Float)); OP(MOD, MOD), (C(Integer), C(Float)); - OP(Eq, EQ), (C(Integer), C(Float), C(String)); + OP(Eq, EQ), (C(Integer), C(Float), C(String), C(Symbol)); OP(Eqq, EQQ), (C(Integer), C(Float), C(Symbol), C(String), C(NilClass), C(TrueClass), C(FalseClass)); OP(LT, LT), (C(Integer), C(Float)); Index: test/ruby/test_symbol.rb =================================================================== --- test/ruby/test_symbol.rb (revision 59249) +++ test/ruby/test_symbol.rb (revision 59250) @@ -514,4 +514,16 @@ class TestSymbol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_symbol.rb#L514 assert_not_equal sym.to_sym.hash, `#{ruby} -e 'puts #{sym.inspect}.to_sym.hash'`.to_i end + + def test_eq_can_be_redefined + assert_in_out_err([], <<-RUBY, ["foo"], []) + class Symbol + def ==(obj) + "foo" + end + end + + puts :a == :a + RUBY + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/