Skip to content

Commit

Permalink
Avoid use of try, use respond_to? instead
Browse files Browse the repository at this point in the history
Because Rails 3's `try` method behavior does not dance with its
successors:

Rails 3:

"".try(:call)
=> NoMethodError: undefined method `call' for "emoji":String

Rails 4+:

"".try(:call)
=> nil
  • Loading branch information
JuanitoFatas committed Jul 1, 2016
1 parent 69b541e commit 08915cf
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/html/pipeline/emoji_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def emoji_image_tag(name)
html_attrs =
default_img_attrs(name).
merge!((context[:img_attrs] || {}).with_indifferent_access).
map { |attr, value| !value.nil? && %(#{attr}="#{value.try(:call, name) || value}") }.
map { |attr, value| !value.nil? && %(#{attr}="#{value.respond_to?(:call) && value.call(name) || value}") }.
reject(&:blank?).join(" ".freeze)

"<img #{html_attrs}>"
Expand Down

0 comments on commit 08915cf

Please sign in to comment.