Is there an inverse 'member?' method in ruby?

前端 未结 5 1035
礼貌的吻别
礼貌的吻别 2020-11-30 12:55

I often find myself checking if some value belongs to some set. As I understand, people normally use Enumerable#member? for this.

end_index = [\         


        
5条回答
  •  猫巷女王i
    2020-11-30 13:24

    Unless you are dealing with elements that have special meaning for === like modules, regexes, etc., you can do pretty much well with case.

    end_index = case word[-1]; when '.', ','; -3 else -2 end
    

提交回复
热议问题