ruby on rails - What is the reason to use ||= instead of = in model to define a constant -
found in current project:
class video < activerecord::base ... valid_video_hosts ||= %w(www.youtube.com youtube.com vimeo.com www.vimeo.com) ... end
usually use simple valid_video_hosts = %w(...) , haven't guess why previous developers used ||=
anybody know benefits?
update
i know ||= in general cases, question defining constant way in model.
||=
used cheap way memoize value, other posters mention. however...
why memoize constant?
the author protecting against warnings when loading source file multiple times. (warning: initialized constant valid_video_hosts
)
Comments
Post a Comment