るりまサーチ

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

別のキーワード

  1. array fill
  2. array sample
  3. array []
  4. array fetch
  5. array count

ライブラリ

クラス

モジュール

検索結果

<< 1 2 > >>

Enumerable#first(n) -> Array (18239.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 -> object | nil (18139.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) #=> []
//}...

1.6.8から1.8.0への変更点(まとめ) (426.0)

1.6.8から1.8.0への変更点(まとめ) * ((<1.6.8から1.8.0への変更点(まとめ)/インタプリタの変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたクラス/モジュール>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたメソッド>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加された定数>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張されたクラス/メソッド(互換性のある変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/変更されたクラス/メソッド(互換性のない変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/文法の変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/正規表現>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Marshal>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Windows 対応>)) * ((<1.6.8から1.8.0への変更点(まとめ)/廃止された(される予定の)機能>)) * ((<1.6.8から1.8.0への変更点(まとめ)/ライブラリ>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張ライブラリAPI>)) * ((<1.6.8から1.8.0への変更点(まとめ)/バグ修正>)) * ((<1.6.8から1.8.0への変更点(まとめ)/サポートプラットフォームの追加>))

...別名) ((<ruby-dev:20197>))

=== Array

: ((<Array#transpose|Array/transpose>)) [new]

追加

: ((<Array#zip|Enumerable/zip>)) [new]
: ((<Enumerable#zip|Enumerable/zip>)) [new]

追加

: ((<Array#fetch|Array/fetch>)) [new]

追加

: ((<Array#insert|Array/insert>)) [new]

追加 (...
...た。

: ((<String#insert|String/insert>)) [new]

追加

(({str[n, 0] = other})) と同じ(ただし self を返す)

=== Struct

: ((<Struct/each_pair>)) [new]

追加。

=== Symbol

: ((<Symbol/Symbol.all_symbols>)) [new]
追加 ((<ruby-dev:12921>))

=== SystemCallError

: ((<Syste...
...るようになりました。

=== Array

: ((<Array#first|Array/first>)) [compat]
: ((<Array#last|Array/last>)) [compat]

省略可能な引数を追加

: ((<Array#push|Array/push>)) [compat]
: ((<Array#unshift|Array/unshift>)) [compat]
: ((<Array#insert|Array/insert>)) [compat]

引数が指...

ruby 1.6 feature (198.0)

ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。

...p /a#{Regexp.quote("#")}b/x =~ "ab"

=> -:3: warning: ambiguous first argument; make sure
ruby 1.6.7 (2002-03-01) [i586-linux]
"#"
0

=> -:3: warning: ambiguous first argument; make sure
ruby 1.6.7 (2002-07-30) [i586-linux]...
...2002-03-10 メソッドの戻り値

以下のメソッドの戻り値が正しくなりました。((<ruby-bugs-ja:PR#205>))

* ((<Enumerable/each_with_index>)) が self を返すようになった(以前は nil)
* ((<Process/Process.setpgrp>)) が返す値が不定だった。
* ((<String...
...from -:14
ruby 1.6.5 (2001-10-05) [i586-linux]

: Subclass of String and Array

String, Array のサブクラスで特定のメソッドを呼ぶと、String, Array
になっていました。

class Foo < String
end
p Foo.new("").class...

NEWS for Ruby 3.0.0 (150.0)

NEWS for Ruby 3.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...nly.

* Array
* The following methods now return Array instances instead of subclass instances when called on subclass instances: 6087
* Array#drop
* Array#drop_while
* Array#flatten
* Array#slice!
* Array#slice / Array#[]
* Array#take
* Array#take_whi...
...le
* Array#uniq
* Array#*
* Can be sliced with Enumerator::ArithmeticSequence

//emlist[][ruby]{
dirty_data = ['--', 'data1', '--', 'data2', '--', 'data3']
dirty_data[(1..).step(2)] # take each second element
# => ["data1", "data2", "data3"]
//}

* Binding
* Binding#eval when c...
...will cause compaction to occur during major collections. At the moment, compaction adds significant overhead to major collections, so please test first! 17176
* Hash
* Hash#transform_keys and Hash#transform_keys! now accept a hash that maps keys to new keys. 16274
* Hash#except has bee...

絞り込み条件を変える

CSV.parse(str, options = Hash.new) -> Array (137.0)

このメソッドは文字列を簡単にパースすることができます。 ブロックを与えた場合は、ブロックにそれぞれの行を渡します。 ブロックを省略した場合は、配列の配列を返します。

...'pp'

s = <<EOS
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
EOS

pp CSV.parse(s)
# => [["id", "first name", "last name", "age"],
# ["1", "taro", "tanaka", "20"],
# ["2", "jiro", "suzuki", "18"]]

CSV.parse(s, headers: true).each do |row|
p [row['first name'], row['age']]...
...=> ["taro", "20"]
# ["jiro", "18"]
//}

//emlist[例][ruby]{
require "csv"

csv = "id|first name|last name|age\n1|taro|tanaka|20\n2|jiro|suzuki|18"
CSV.parse(csv, col_sep: '|') do |row|
p [row[1], row[2]]
end
# => ["first name", "last name"]
# => ["taro", "tanaka"]
# => ["jiro", "suzuki"]
//}...

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

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

...数です。

//emlist[][ruby]{
str = "xyz"

enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
modu...
...e
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...

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

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

...数です。

//emlist[][ruby]{
str = "xyz"

enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
modu...
...e
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...

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

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

...数です。

//emlist[][ruby]{
str = "xyz"

enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
modu...
...e
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...

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

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

...数です。

//emlist[][ruby]{
str = "xyz"

enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
modu...
...e
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...

絞り込み条件を変える

<< 1 2 > >>