るりまサーチ

最速Rubyリファレンスマニュアル検索!
278件ヒット [1-100件を表示] (0.059秒)

別のキーワード

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

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 > >>

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

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

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

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

exclude_end が真ならば終端を含まない範囲オブジェクトを生
成します。exclude_end 省略時には終端を含みます。

@param first 最初のオブジェクト
@param last 最後のオブ...
...ジェクト
@param exclude_end 真をセットした場合終端を含まない範囲オブジェクトを生成します

@raise ArgumentError first <=> last が nil の場合に発生します

//emlist[例: 整数の範囲オブジェクトの場合][ruby]{
Range.new(1, 10) # => 1..10
Rang...
...new(Date.today, Date.today >> 1).each {|d| puts d }
# => 2017-09-16
# 2017-09-17
# ...
# 2017-10-16
//}

//emlist[例: IPアドレスの範囲オブジェクトの場合][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
#...

Object#enum_for(method = :each, *args) -> Enumerator (8128.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 (8128.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 (8128.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 (8128.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...

Enumerator::Lazy#enum_for(method = :each, *args) -> Enumerator::Lazy (8122.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...f n < 0
if block_given?
each
do |*val|
n.times { yield *val }
end
else
to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

#...

Enumerator::Lazy#enum_for(method = :each, *args) {|*args| block} -> Enumerator::Lazy (8122.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...f n < 0
if block_given?
each
do |*val|
n.times { yield *val }
end
else
to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

#...

Enumerator::Lazy#to_enum(method = :each, *args) -> Enumerator::Lazy (8122.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...f n < 0
if block_given?
each
do |*val|
n.times { yield *val }
end
else
to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

#...

絞り込み条件を変える

<< 1 2 3 > >>