class Module
Public Instance Methods
deprecate_public(meth, msg=nil)
click to toggle source
Allow but deprecate public method calls to meth
, if meth
is protected or private. meth
can be an array of method name strings or symbols to handle multiple methods at once. If msg
is specified, it can be used to customize the warning printed.
# File lib/deprecate_public.rb 28 def deprecate_public(meth, msg=nil) 29 include DeprecatePublic 30 31 Array(meth).each do |m| 32 message = (msg || "calling #{name}##{m} using deprecated public interface").dup.freeze 33 message_meth = :"_deprecated_public_message_#{m}" 34 define_method(message_meth){message} 35 private message_meth 36 end 37 38 nil 39 end
deprecate_public_constant(const, msg=nil)
click to toggle source
Allow but deprecate public constant access to const
, if const
is a private constant. const
can be an array of method name strings or symbols to handle multiple methods at once. If msg
is specified, it can be used to customize the warning printed.
# File lib/deprecate_public.rb 61 def deprecate_public_constant(const, msg=nil) 62 extend DeprecatePublicConstant 63 64 Array(const).each do |c| 65 message = (msg || "accessing #{name}::#{c} using deprecated public interface").dup.freeze 66 message_meth = :"_deprecated_public_constant_message_#{c}" 67 define_singleton_method(message_meth){message} 68 singleton_class.send(:private, message_meth) 69 end 70 71 nil 72 end