Skip to content

Commit

Permalink
Merge pull request #750 from stripe/brandur-warn-on-remove-error
Browse files Browse the repository at this point in the history
Catch error and warn if unable to remove a method
  • Loading branch information
brandur-stripe committed Mar 18, 2019
2 parents df8c141 + 8702e71 commit c1894e8
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/stripe/stripe_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,25 @@ def remove_accessors(keys)

# Remove methods for the accessor's reader and writer.
[k, :"#{k}=", :"#{k}?"].each do |method_name|
remove_method(method_name) if method_defined?(method_name)
next unless method_defined?(method_name)

begin
remove_method(method_name)
rescue NameError
# In some cases there can be a method that's detected with
# `method_defined?`, but which cannot be removed with
# `remove_method`, even though it's on the same class. The only
# case so far that we've noticed this is when a class is
# reopened for monkey patching:
#
# https://github.com/stripe/stripe-ruby/issues/749
#
# Here we swallow that error and issue a warning so at least
# the program doesn't crash.
$stderr.puts("WARNING: Unable to remove method `#{method_name}`; " \
"if custom, please consider renaming to a name that doesn't " \
"collide with an API property name.")
end
end
end
end
Expand Down

0 comments on commit c1894e8

Please sign in to comment.