Mat*_*iby 3 ruby rubygems ruby-on-rails
我一直在挖掘一些红宝石宝石代码,我遇到了这些并且不确定它们意味着什么
def success?
!!@success
end
def failure?
!@success
end
cattr_accessor :test_response
Run Code Online (Sandbox Code Playgroud)
最后这段代码
class_inheritable_accessor :attributes
self.attributes = []
def self.attribute(name, options={})
top_level_name = name.to_s.split(".").last.underscore
define_method top_level_name do
read_attribute name
end
Run Code Online (Sandbox Code Playgroud)
如果你只知道一两个那么好......我只想了解他们......谢谢
!!是一个"强制转换为布尔".!否定一个价值,!!否定否定的价值.因此!!将任何值转换为布尔值.
> 5
=> 5
> !5
=> false
> !!5
=> true
> !!5 == true
=> true
Run Code Online (Sandbox Code Playgroud)