module Katello::RemoveUnsupportedBindingDefaults
Public Class Methods
patch(klass, *attributes)
click to toggle source
Prepends an initializer to klass that unsets each of attributes that the binding defaulted rather than the caller supplying it. The attribute has to be unset (not set to nil), since to_hash emits an explicit null for nullable attributes whose instance variable is defined.
Calls superclass method
# File lib/monkeys/remove_unsupported_binding_defaults.rb, line 27 def self.patch(klass, *attributes) klass.prepend(Module.new do define_method(:initialize) do |attrs = {}| super(attrs) supplied = attrs.is_a?(Hash) ? attrs.keys.map(&:to_sym) : [] (attributes - supplied).each do |attribute| ivar = :"@#{attribute}" remove_instance_variable(ivar) if instance_variable_defined?(ivar) end end end) end