我一直在研究一些 ruby gem 代码,我遇到了这些但不确定它们是什么意思
def success?
!!@success
end
def failure?
!@success
end
cattr_accessor :test_response
最后是这段代码
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
如果你只知道一两个也没关系...我只想了解它们...谢谢
最佳答案
!!
是“转换为 bool 值”。 !
取反一个值,!!
取反被取反的值。因此 !!
将任何值转换为 bool 值。
> 5
=> 5
> !5
=> false
> !!5
=> true
> !!5 == true
=> true
关于ruby-on-rails - 是什么 !!和 Ruby 中的其他一些东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3852328/