るりまサーチ

最速Rubyリファレンスマニュアル検索!
45件ヒット [1-45件を表示] (0.227秒)
トップページ > クエリ:_builtin[x] > クエリ:new[x] > クラス:Range[x]

別のキーワード

  1. _builtin inspect
  2. _builtin []
  3. _builtin to_s
  4. _builtin each

ライブラリ

キーワード

検索結果

Range.new(first, last, exclude_end = false) -> Range (26168.0)

first から last までの範囲オブジェクトを生成して返しま す。

...ist[例: 整数の範囲オブジェクトの場合][ruby]{
Range
.new(1, 10) # => 1..10
Range
.new(1, 10, true) # => 1...10
//}

//emlist[例: 日付オブジェクトの範囲オブジェクトの場合][ruby]{
require 'date'
Range
.new(Date.today, Date.today >> 1).each {|d| puts d }
# => 2017-...
...[ruby]{
require 'ipaddr'
Range
.new(IPAddr.new("192.0.2.1"), IPAddr.new("192.0.2.3")).each {|ip| puts ip}
# => 192.0.2.1
# 192.0.2.2
# 192.0.2.3
//}

//emlist[例: 自作のオブジェクトの場合][ruby]{
MyInteger = Struct.new(:value) do
def succ
self.class.new(value + 1)
end

de...
...f <=>(other)
value <=> other.value
end

def to_s
value.to_s
end
end
Range
.new(MyInteger.new(1), MyInteger.new(3)).each {|i| puts i }
# => 1
# 2
# 3
//}...

Range#entries -> Array (8013.0)

self を配列に変換します。

...e 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#to_a -> Array (8013.0)

self を配列に変換します。

...e 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#==(other) -> bool (8007.0)

指定された other が Range クラスのインスタンスであり、 始端と終端が == メソッドで比較して等しく、Range#exclude_end? が同じ場合に true を返します。そうでない場合に false を返します。

...指定された other が Range クラスのインスタンスであり、
始端と終端が == メソッドで比較して等しく、Range#exclude_end? が同じ場合に
true を返します。そうでない場合に false を返します。

@param other 自身と比較したいオブジェ...
...クトを指定します。

//emlist[例][ruby]{
p (1..2) == (1..2) # => true
p (1..2) == (1...2) # => false
p (1..2) == Range.new(1.0, 2.0) # => true
//}...

Range#eql?(other) -> bool (8007.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
//}...

絞り込み条件を変える