Object.try is an ActiveSupport method which lets you attempt to invoke a method on an object without worrying about a NoMethodError being raised.
file_type = file_types.detect { |key,| name.include? key }.try(:last)
Nice!
blog comments powered by Disqus