るりまサーチ

最速Rubyリファレンスマニュアル検索!
348件ヒット [1-100件を表示] (0.053秒)
トップページ > クエリ:object[x] > クエリ:nil[x] > クエリ:first[x]

別のキーワード

  1. objectspace each_object
  2. _builtin each_object
  3. object enum_for
  4. object to_enum
  5. object send

ライブラリ

クラス

モジュール

検索結果

<< 1 2 3 ... > >>

Array#first -> object | nil (18343.0)

配列の先頭の要素を返します。要素がなければ nil を返します。

...配列の先頭の要素を返します。要素がなければ nil を返します。

//emlist[例][ruby]{
p [0, 1, 2].first #=> 0
p [].first #=> nil
//}

@see Array#last...

Enumerable#first -> object | nil (18340.0)

Enumerable オブジェクトの最初の要素、もしくは最初の n 要素を返します。

...引数を指定しない形式では nil を返します。
引数を指定する形式では、空の配列を返します。

@param n 取得する要素数。

//emlist[例][ruby]{
e = "abcd".each_byte
e.first #=> 97
e.first(2) #=> [97,98]
e = "".each_byte
e.first #=> nil
e.first(2) #=> []
//}...

Enumerable#first(n) -> Array (18140.0)

Enumerable オブジェクトの最初の要素、もしくは最初の n 要素を返します。

...引数を指定しない形式では nil を返します。
引数を指定する形式では、空の配列を返します。

@param n 取得する要素数。

//emlist[例][ruby]{
e = "abcd".each_byte
e.first #=> 97
e.first(2) #=> [97,98]
e = "".each_byte
e.first #=> nil
e.first(2) #=> []
//}...

Array#first(n) -> Array (18138.0)

先頭の n 要素を配列で返します。n は 0 以上でなければなりません。

...指定した場合に発生します。

@raise ArgumentError n が負値の場合発生します。

//emlist[例][ruby]{
ary = [0, 1, 2]
p ary.first(0)
p ary.first(1)
p ary.first(2)
p ary.first(3)
p ary.first(4)
# => []
# [0]
# [0, 1]
# [0, 1, 2]
# [0, 1, 2]
//}

@see Array#last...

Range#first -> object (15262.0)

始端の要素を返します。 始端を持たない範囲オブジェクトの場合、begin はnilを返しますが, first は例外 RangeError が発生します。

...、begin はnilを返しますが, 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...

絞り込み条件を変える

Range#first(n) -> [object] (15217.0)

最初の n 要素を返します。範囲内に要素が含まれない場合は空の配列を返します。

...に整数以外の(暗黙の型変換が行えない)オブジェクトを
指定した場合に発生します。

@raise ArgumentError n に負の数を指定した場合に発生します。

//emlist[例][ruby]{
(10..20).first(3) # => [10, 11, 12]
//}

@see Range#last, 12697...

Object#enum_for(method = :each, *args) -> Enumerator (9012.0)

Enumerator.new(self, method, *args) を返します。

...!" if n < 0
unless block_given?
# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
end
end
each do |*val|
n.times { yield *val }...
...end
end
end

%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
//}

@see Enumerator, Enumerator#size...

Object#enum_for(method = :each, *args) {|*args| ... } -> Enumerator (9012.0)

Enumerator.new(self, method, *args) を返します。

...!" if n < 0
unless block_given?
# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
end
end
each do |*val|
n.times { yield *val }...
...end
end
end

%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
//}

@see Enumerator, Enumerator#size...

Object#to_enum(method = :each, *args) -> Enumerator (9012.0)

Enumerator.new(self, method, *args) を返します。

...!" if n < 0
unless block_given?
# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
end
end
each do |*val|
n.times { yield *val }...
...end
end
end

%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
//}

@see Enumerator, Enumerator#size...

Object#to_enum(method = :each, *args) {|*args| ... } -> Enumerator (9012.0)

Enumerator.new(self, method, *args) を返します。

...!" if n < 0
unless block_given?
# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
end
end
each do |*val|
n.times { yield *val }...
...end
end
end

%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
//}

@see Enumerator, Enumerator#size...

絞り込み条件を変える

<< 1 2 3 ... > >>