Why does Ruby not Symbol#=~ (regex match operator)?

后端 未结 1 1348
抹茶落季
抹茶落季 2021-01-12 13:59

Ruby doesn\'t automatically stringify symbols when performing a regex match on them, which is easy to do when you have variables containing symbols and you forget that you n

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-12 14:41

    I don't know the reason why it was decided that 1.8 should behave this way, but 1.9 changed in that regard:

    >> RUBY_VERSION #=> "1.9.2"
    >> :this =~ /./ #=> 0
    >> :this =~ /is/ #=> 2
    

    0 讨论(0)
提交回复
热议问题