22件ヒット
[1-22件を表示]
(0.313秒)
クラス
- BasicObject (11)
- Module (11)
検索結果
-
Module
# attr _ reader(*name) -> [Symbol] (26216.0) -
インスタンス変数 name の読み取りメソッドを定義します。
...タンス変数 name の読み取りメソッドを定義します。
//emlist[例][ruby]{
class User
attr_reader :name # => [:name]
# 複数の名前を渡すこともできる
attr_reader :id, :age # => [:id, :age]
end
//}
このメソッドで定義されるメソッドの定義は以下... -
Module
# attr _ reader(*name) -> nil (26204.0) -
インスタンス変数 name の読み取りメソッドを定義します。
インスタンス変数 name の読み取りメソッドを定義します。
このメソッドで定義されるメソッドの定義は以下の通りです。
//emlist[例][ruby]{
def name
@name
end
//}
@param name String または Symbol を 1 つ以上指定します。 -
BasicObject
# ! -> bool (8021.0) -
オブジェクトを真偽値として評価し、その論理否定を返します。
...トが偽であれば真、さもなくば偽
//emlist[例][ruby]{
class NegationRecorder < BasicObject
def initialize
@count = 0
end
attr_reader :count
def !
@count += 1
super
end
end
recorder = 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
#=> "another false is a truth"
//}...