検索結果
先頭5件
-
Object
# ==(other) -> bool (18125) -
オブジェクトと other が等しければ真を返します。
...。
デフォルトでは equal? と同じオブジェクト
の同一性判定になっています。
@param other 比較するオブジェクトです。
p("foo" == "bar") #=> false
p("foo" == "foo") #=> true
p(4 == 4) #=> true
p(4 == 4.0) #=> true
@see Object#equal?,Object#eql?... -
Object
# ===(other) -> bool (12201) -
メソッド Object#== の別名です。 case 式で使用されます。このメソッドは case 式での振る舞いを考慮して、 各クラスの性質に合わせて再定義すべきです。
...メソッド Object#== の別名です。
case 式で使用されます。このメソッドは case 式での振る舞いを考慮して、
各クラスの性質に合わせて再定義すべきです。
一般的に所属性のチェックを実現するため適宜再定義されます。
when......節の式をレシーバーとして === を呼び出すことに注意してください。
また Enumerable#grep でも使用されます。
@param other 比較するオブジェクトです。
age = 12
result =
case age
when 0 .. 2
"baby"
when 3 .. 6
"little child"
wh......String class. But don't hit."
else
"unknown"
end
end
puts check([]) #=> unknown
puts check("mash-up in Ruby on Rails") #=> instance of String class. But not hit...
puts check("<Ruby's world>") #=> hit! <Ruby's world>
@see Object#==, Range#===, Module#===, Enumerable#grep... -
Object
# clone -> object (19) -
オブジェクトの複製を作成して返します。
...equal?(obj)) #=> true
p(obj == obj) #=> true
p(obj.tainted?) #=> true
p(obj.frozen?) #=> true
p(obj.respond_to?(:fuga)) #=> true
obj_c = obj.clone
p(obj.equal?(obj_c)) #=> false
p(obj == obj_c) #=> true
p(obj_......obj.dup
p(obj.equal?(obj_d)) #=> false
p(obj == obj_d) #=> true
p(obj_d.tainted?) #=> true
p(obj_d.frozen?) #=> false
p(obj_d.respond_to?(:fuga)) #=> false
@see Object#initialize_copy
==== 深いコピーと浅いコピー
clone や dup はオ... -
Object
# dup -> object (19) -
オブジェクトの複製を作成して返します。
...equal?(obj)) #=> true
p(obj == obj) #=> true
p(obj.tainted?) #=> true
p(obj.frozen?) #=> true
p(obj.respond_to?(:fuga)) #=> true
obj_c = obj.clone
p(obj.equal?(obj_c)) #=> false
p(obj == obj_c) #=> true
p(obj_......obj.dup
p(obj.equal?(obj_d)) #=> false
p(obj == obj_d) #=> true
p(obj_d.tainted?) #=> true
p(obj_d.frozen?) #=> false
p(obj_d.respond_to?(:fuga)) #=> false
@see Object#initialize_copy
==== 深いコピーと浅いコピー
clone や dup はオ... -
Object
# eql?(other) -> bool (7) -
オブジェクトと other が等しければ真を返します。Hash で二つのキー が等しいかどうかを判定するのに使われます。
...かを判定するのに使われます。
このメソッドは各クラスの性質に合わせて再定義すべきです。
多くの場合、 == と同様に同値性の判定をするように再定義されていますが、
適切にキー判定ができるようにより厳しくなって......時には Object#hash メソッ
ドも再定義しなければなりません。
@param other 比較するオブジェクトです。
p("foo".eql?("bar")) #=> false
p("foo".eql?("foo")) #=> true
p(4.eql?(4)) #=> true
p(4.eql?(4.0)) #=> false
@see Object#hash,Object#equal?,Object#==... -
Object
# hash -> Fixnum (7) -
オブジェクトのハッシュ値を返します。Hash クラスでオブジェク トを格納するのに用いられています。
...でオブジェク
トを格納するのに用いられています。
メソッド hash は Object#eql? と組み合わせて Hash クラスで利用されます。その際
A.eql?(B) ならば A.hash == B.hash
の関係を必ず満たしていなければいけません。eql? を再定義し......た時には必ずこちらも合わせ
て再定義してください。
デフォルトでは、Object#object_id と同じ値を返します。
ただし、Fixnum, Symbol, String だけは組込みのハッ
シュ関数が使用されます(これを変えることはできません)。
hash を......す。Fixnumに収まらない場合は切り捨てられます。
p self.hash #=> 21658870
p 0.hash #=> 1
p 0.0.hash #=> 0
p nil.hash #=> 4
p "ruby".hash #=> -241670986
p "ruby".hash #=> -241670986
p :ruby.hash #=> 103538
p :ruby.hash #=> 103538
@see Object#eql?,Object#__id__... -
Object
# tap {|x| . . . } -> self (7) -
self を引数としてブロックを評価し、self を返します。
...的です。
(1..10) .tap {|x| puts "original: #{x.inspect}"}.
to_a .tap {|x| puts "array: #{x.inspect}"}.
select {|x| x % 2 == 0} .tap {|x| puts "evens: #{x.inspect}"}.
map { |x| x * x } .tap {|x| puts "squares: #{x.inspect}"}...
