Ruby on rails 什么是';Httparty';源代码
Ruby on rails 什么是';Httparty';源代码,ruby-on-rails,httparty,Ruby On Rails,Httparty,lib/httparty.rb中的代码 module HTTParty module AllowedFormatsDeprecation def const_missing(const) if const.to_s =~ /AllowedFormats$/ Kernel.warn("Deprecated: Use HTTParty::Parser::SupportedFormats") HTTParty::Parser::Supported
lib/httparty.rb中的代码
module HTTParty
module AllowedFormatsDeprecation
def const_missing(const)
if const.to_s =~ /AllowedFormats$/
Kernel.warn("Deprecated: Use HTTParty::Parser::SupportedFormats")
HTTParty::Parser::SupportedFormats
else
super
end
end
end
extend AllowedFormatsDeprecation
def self.included(base)
base.extend ClassMethods
base.send :include, HTTParty::ModuleInheritableAttributes
base.send(:mattr_inheritable, :default_options)
base.send(:mattr_inheritable, :default_cookies)
base.instance_variable_set("@default_options", {})
base.instance_variable_set("@default_cookies", CookieHash.new)
end
module ClassMethods
extend AllowedFormatsDeprecation
...
我想知道在这两个地方,代码扩展允许的格式预处理
的目的是什么
我不这么认为
module ClassMethods
extend AllowedFormatsDeprecation
它在这里有任何意义
我希望能有一个好的解释……。经过对相关技能的深入研究,我明白了。
AllowedFormatsPrecision
的第一个扩展是处理这种常量引用
HTTParty::AllowedFormats
AllowedFormatsPrecision
的第二个扩展用于ClassMethods
方法中的常量引用。像
module ClassMethods
def test
AllowedFormats
end
end
模块的include
或extend
不能改变该模块的常量引用方式,因此应在模块中定义const_missing
方法