ライブラリ
- ビルトイン (383)
-
json
/ add / range (11)
検索結果
先頭5件
-
Range
# each {|item| . . . } -> self (2.0) -
範囲内の要素に対して繰り返します。
...範囲内の要素に対して繰り返します。
Range#each は各要素の succ メソッドを使用してイテレーションするようになりました。
@raise TypeError succ メソッドを持たないクラスの範囲オブジェクトに対してこのメソッドを呼んだ場... -
Range
# end -> object (2.0) -
終端の要素を返します。範囲オブジェクトが終端を含むかどうかは関係ありま せん。
...終端の要素を返します。範囲オブジェクトが終端を含むかどうかは関係ありま
せん。
//emlist[例][ruby]{
(10..20).last # => 20
(10...20).last # => 20
//}
@see Range#begin... -
Range
# entries -> Array (2.0) -
self を配列に変換します。
...self を配列に変換します。
@raise RangeError 終端のない Range オブジェクトを変換しようとしたときに発生します。
//emlist[例][ruby]{
p (5..0).to_a # => []
p (0..3).to_a # => [0, 1, 2, 3]
p ('a'..'c').to_a # => ["a", "b", "c"]
p (:a..:d).to_a # => [......:a, :b, :c, :d]
require 'date'
p (Date.new(1965, 4, 14) .. Date.new(1965, 4, 14)).to_a # => [#<Date: 1965-04-14 ((2438865j,0s,0n),+0s,2299161j)>]
(1..).to_a # RangeError: cannot convert endless range to an array
//}... -
Range
# eql?(other) -> bool (2.0) -
指定された other が Range クラスのインスタンスであり、 始端と終端が eql? メソッドで比較して等しく、Range#exclude_end? が同じ場合に true を返します。そうでない場合に false を返します。
...指定された other が Range クラスのインスタンスであり、
始端と終端が eql? メソッドで比較して等しく、Range#exclude_end? が同じ場合に
true を返します。そうでない場合に false を返します。
@param other 自身と比較したいオブジェ......クトを指定します。
//emlist[例][ruby]{
p (1..2).eql?(1..2) # => true
p (1..2).eql?(1...2) # => false
p (1..2).eql?(Range.new(1.0, 2.0)) # => false
//}... -
Range
# exclude _ end? -> bool (2.0) -
範囲オブジェクトが終端を含まないとき真を返します。
範囲オブジェクトが終端を含まないとき真を返します。
//emlist[例][ruby]{
(1..5).exclude_end? # => false
(1...5).exclude_end? # => true
//} -
Range
# first -> object (2.0) -
始端の要素を返します。 始端を持たない範囲オブジェクトの場合、begin はnilを返しますが, first は例外 RangeError が発生します。
...しますが, first は例外 RangeError が発生します。
//emlist[例][ruby]{
# 始端を持つ場合
p (1..5).begin # => 1
p (1..0).begin # => 1
p (1..5).first # => 1
p (1..0).first # => 1
# 始端を持たない場合
p (..5).begin #=> nil
p (..5).first #=> RangeError
//}
@see Range#end... -
Range
# first(n) -> [object] (2.0) -
最初の n 要素を返します。範囲内に要素が含まれない場合は空の配列を返します。
...に整数以外の(暗黙の型変換が行えない)オブジェクトを
指定した場合に発生します。
@raise ArgumentError n に負の数を指定した場合に発生します。
//emlist[例][ruby]{
(10..20).first(3) # => [10, 11, 12]
//}
@see Range#last, 12697... -
Range
# hash -> Integer (2.0) -
始端と終端のハッシュ値と Range#exclude_end? の値からハッシュ値を計算して整数として返します。
...始端と終端のハッシュ値と Range#exclude_end? の値からハッシュ値を計算して整数として返します。
//emlist[例][ruby]{
p (1..2).hash # => 5646
p (1...2).hash # => 16782863
//}... -
Range
# include?(obj) -> bool (2.0) -
obj が範囲内に含まれている時に true を返します。 そうでない場合は、false を返します。
...false を返します。
Range#=== は主に case 式での比較に用いられます。
<=> メソッドによる演算により範囲内かどうかを判定するには Range#cover? を使用してください。
始端・終端・引数が数値であれば、 Range#cover? と同様の動き......クトを指定します。
//emlist[例][ruby]{
p ("a" .. "c").include?("b") # => true
p ("a" .. "c").include?("B") # => false
p ("a" .. "c").include?("ba") # => false
p ("a" .. "c").cover?("ba") # => true
p (1 .. 3).include?(1.5) # => true
//}
@see d:spec/control#case
@see Range#cover?......返します。
<=> メソッドによる演算により範囲内かどうかを判定するには Range#cover? を使用してください。
始端・終端・引数が数値であれば、 Range#cover? と同様の動きをします。
@param obj 比較対象のオブジェクトを指定し......ます。
//emlist[例][ruby]{
p ("a" .. "c").include?("b") # => true
p ("a" .. "c").include?("B") # => false
p ("a" .. "c").include?("ba") # => false
p ("a" .. "c").cover?("ba") # => true
p (1 .. 3).include?(1.5) # => true
//}
@see d:spec/control#case
@see Range#cover?, Range#===... -
Range
# inspect -> String (2.0) -
self を文字列に変換します(始端と終端のオブジェクトは #inspect メソッド で文字列に変換されます)。
...self を文字列に変換します(始端と終端のオブジェクトは #inspect メソッド
で文字列に変換されます)。
@see Range#to_s
//emlist[例][ruby]{
(1..5).inspect # => "1..5"
("1".."5").inspect # => "\"1\"..\"5\""
//}...