11件ヒット
[1-11件を表示]
(0.176秒)
ライブラリ
- ビルトイン (11)
検索結果
-
BasicObject
# ! -> bool (3125.0) -
オブジェクトを真偽値として評価し、その論理否定を返します。
...self が nil または false であれば真を、さもなくば偽を返します。
主に論理式の評価に伴って副作用を引き起こすことを目的に
再定義するものと想定されています。
このメソッドを再定義しても Ruby の制御式において nil や......false 以外が偽として
扱われることはありません。
@return オブジェクトが偽であれば真、さもなくば偽
//emlist[例][ruby]{
class NegationRecorder < BasicObject
def initialize
@count = 0
end
attr_reader :count
def !
@count += 1
super
end
e......= NegationRecorder.new
!recorder
!!!!!!!recorder
puts 'hoge' if !recorder
puts recorder.count #=> 3
//}
//emlist[例][ruby]{
class AnotherFalse < BasicObject
def !
true
end
end
another_false = AnotherFalse.new
# another_falseは*真*
puts "another false is a truth" if another_false
#=> "...