What is the “=~” operator in Ruby?

前端 未结 7 680
情深已故
情深已故 2020-12-01 09:56

I saw this on a screencast and couldn\'t figure out what it was. Reference sheets just pile it in with other operators as a general pattern match operator.

7条回答
  •  感动是毒
    2020-12-01 10:32

    Well, the reference is correct, it is the "matches this regex" operator.

    if var =~ /myregex/ then something end
    

提交回复
热议问题