The Ruby %r{ } expression

前端 未结 5 1152
暗喜
暗喜 2020-12-04 09:21

In a model there is a field

validates :image_file_name, :format => { :with => %r{\\.(gif|jpg|jpeg|png)$}i

It looks pretty odd for me.

5条回答
  •  囚心锁ツ
    2020-12-04 09:55

    It mean that image_file_name must end ($) with dot and one of gif, jpg, jpeg or png.

    Yes %r{} mean exactly the same as // but in %r{} you don't need to escape /.

提交回复
热议问题