るりまサーチ

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

別のキーワード

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

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

Enumerator::Lazy#map {|item| ... } -> Enumerator::Lazy (23237.0)

Enumerable#map と同じですが、配列ではなくEnumerator::Lazy を返します。

...ble#map と同じですが、配列ではなくEnumerator::Lazy を返します。

@raise ArgumentError ブロックを指定しなかった場合に発生します。

//emlist[例][ruby]{
1.step.lazy.map{ |n| n % 3 == 0 }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator: 1:step>>:map>

1...
....step.lazy.collect{ |n| n.succ }.take(10).force
# => [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
//}

@see Enumerable#map...

Array#map {|item| ... } -> [object] (23216.0)

各要素に対してブロックを評価した結果を全て含む配列を返します。

...要素に対してブロックを評価した結果を全て含む配列を返します。

ブロックを省略した場合は Enumerator を返します。

//emlist[例][ruby]{
# すべて 3 倍にする
p [1, 2, 3].map {|n| n * 3 } # => [3, 6, 9]
//}

@see Enumerable#collect, Enumerable#map...
...してブロックを評価した結果を全て含む配列を返します。

ブロックを省略した場合は Enumerator を返します。

//emlist[例][ruby]{
# すべて 3 倍にする
p [1, 2, 3].map {|n| n * 3 } # => [3, 6, 9]
//}

@see Hash#to_h, Enumerable#collect, Enumerable#map...

Enumerable#map {|item| ... } -> [object] (23216.0)

各要素に対してブロックを評価した結果を全て含む配列を返します。

...全て含む配列を返します。

ブロックを省略した場合は Enumerator を返します。

//emlist[例][ruby]{
# すべて 3 倍にした配列を返す
p (1..3).map {|n| n * 3 } # => [3, 6, 9]
p (1..3).collect { "cat" } # => ["cat", "cat", "cat"]
//}

@see Array#collect, Array#map...
...配列を返します。

ブロックを省略した場合は Enumerator を返します。

//emlist[例][ruby]{
# すべて 3 倍にした配列を返す
p (1..3).map {|n| n * 3 } # => [3, 6, 9]
p (1..3).collect { "cat" } # => ["cat", "cat", "cat"]
//}

@see Hash#to_h, Array#collect, Array#map...

Enumerator::Lazy#filter_map {|item| ... } -> Enumerator::Lazy (20243.0)

Enumerable#filter_map と同じですが、配列ではなく Enumerator::Lazy を返します。

...filter_map と同じですが、配列ではなく Enumerator::Lazy を返します。

@raise ArgumentError ブロックを指定しなかった場合に発生します。

//emlist[例][ruby]{
1.step.lazy.filter_map { |n| n * 2 if n.even? }
# => #<Enumerator::Lazy: #<Enumerator::Lazy: (1.step)>:fi...
...lter_map>

1.step.lazy.filter_map { |n| n * 2 if n.even? }.take(10).force
# => [4, 8, 12, 16, 20, 24, 28, 32, 36, 40]
//}

@see Enumerable#filter_map...

Enumerable#filter_map -> Enumerator (20234.0)

各要素に対してブロックを評価した値のうち、真であった値の 配列を返します。

...対してブロックを評価した値のうち、真であった値の
配列を返します。

ブロックを省略した場合は Enumerator を返します。

//emlist[例][ruby]{
(1..10).filter_map { |i| i * 2 if i.even? } #=> [4, 8, 12, 16, 20]
//}

@see Enumerable#filter, Enumerable#map...

絞り込み条件を変える

Enumerable#filter_map {|item| ... } -> [object] (20234.0)

各要素に対してブロックを評価した値のうち、真であった値の 配列を返します。

...対してブロックを評価した値のうち、真であった値の
配列を返します。

ブロックを省略した場合は Enumerator を返します。

//emlist[例][ruby]{
(1..10).filter_map { |i| i * 2 if i.even? } #=> [4, 8, 12, 16, 20]
//}

@see Enumerable#filter, Enumerable#map...

Encoding.locale_charmap -> String | nil (17202.0)

ロケールエンコーディングを決定するために用いる、locale charmap 名を返します。nl_langinfo 等がない環境では nil を、miniruby では ASCII_8BIT を返します。

...harmap 名を返します。nl_langinfo 等がない環境では nil を、miniruby では ASCII_8BIT を返します。

//emlist[Debian GNU/Linux + LANG=C][ruby]{
Encoding.locale_charmap #=> "ANSI_X3.4-1968"
//}

//emlist[LANG=ja_JP.EUC-JP][ruby]{
Encoding.locale_charmap #=> "EUC-JP"
//}

//emlist...
...[SunOS 5 + LANG=C][ruby]{
Encoding.locale_charmap #=> "646"
//}

//emlist[SunOS 5 + LANG=ja][ruby]{
Encoding.locale_charmap #=> "eucJP"
//}

@see charmap(5)...

IO.binwrite(path, string, offset=nil) -> Integer (14320.0)

path で指定されるファイルを開き、string を書き込み、 閉じます。

...path で指定されるファイルを開き、string を書き込み、
閉じます。

ファイルを開くときの mode が "rb:ASCII-8BIT" で、バイナリモードが有効
である点以外は IO.write と同じです。

Kernel.#open と同様 path の先頭が "|" ならば、"|" に...
...ル名文字列
@param string 書き込む文字列
@param offset 書き込み開始位置

//emlist[例][ruby]{
# 8x8の真っ白なPNG画像データ。
png = 'iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAAAAADhZOFXAAAADklEQVQIW2P4DwUMlDEA98A/wTjP
QBoAAAAASUVORK5CYII='.unpack('m').first

# 期待する先頭...
...ck('C*').map {|c| '%02x' % c }.join(' ')
# => 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52

# binwriteを使用した場合: どの環境でも正しく保存できる。
I
O.binwrite('white.binmode.png', png)
puts IO.binread('white.binmode.png', 16).unpack('C*').map {|c| '%02x' % c }.join(' ')
#...

Kernel.#caller_locations(range) -> [Thread::Backtrace::Location] | nil (14214.0)

現在のフレームを Thread::Backtrace::Location の配列で返します。引 数で指定した値が範囲外の場合は nil を返します。

...現在のフレームを Thread::Backtrace::Location の配列で返します。引
数で指定した値が範囲外の場合は nil を返します。

@param start 開始フレームの位置を数値で指定します。

@param length 取得するフレームの個数を指定します。

@pa...
...

//emlist[例][ruby]{
def test1(start, length)
locations = caller_locations(start, length)
p locations
p locations.map(&:lineno)
p locations.map(&:path)
end

def test2(start, length)
test1(start, length)
end

def test3(start, length)
test2(start, length)
end

caller_locations # => []...
...1, nil)
# => ["/Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `test3'", "/Users/user/test.rb:17:in `<main>'"]
# => [9, 13, 17]
# => ["/Users/user/test.rb", "/Users/user/test.rb", "/Users/user/test.rb"]
test3(1, 2)
# => ["/Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `t...

Kernel.#caller_locations(start = 1, length = nil) -> [Thread::Backtrace::Location] | nil (14214.0)

現在のフレームを Thread::Backtrace::Location の配列で返します。引 数で指定した値が範囲外の場合は nil を返します。

...現在のフレームを Thread::Backtrace::Location の配列で返します。引
数で指定した値が範囲外の場合は nil を返します。

@param start 開始フレームの位置を数値で指定します。

@param length 取得するフレームの個数を指定します。

@pa...
...

//emlist[例][ruby]{
def test1(start, length)
locations = caller_locations(start, length)
p locations
p locations.map(&:lineno)
p locations.map(&:path)
end

def test2(start, length)
test1(start, length)
end

def test3(start, length)
test2(start, length)
end

caller_locations # => []...
...1, nil)
# => ["/Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `test3'", "/Users/user/test.rb:17:in `<main>'"]
# => [9, 13, 17]
# => ["/Users/user/test.rb", "/Users/user/test.rb", "/Users/user/test.rb"]
test3(1, 2)
# => ["/Users/user/test.rb:9:in `test2'", "/Users/user/test.rb:13:in `t...

絞り込み条件を変える

Thread::Backtrace::Location#inspect -> String (14208.0)

Thread::Backtrace::Location#to_s の結果を人間が読みやすいような文 字列に変換したオブジェクトを返します。

...e::Location#to_s の結果を人間が読みやすいような文
字列に変換したオブジェクトを返します。

//emlist[例][ruby]{
# foo.rb
class Foo
attr_accessor :locations
def initialize(skip)
@locations = caller_locations(skip)
end
end

Foo.new(0..2).locations.map do |ca...
...ll|
puts call.inspect
end

# => "path/to/foo.rb:5:in `initialize'"
# "path/to/foo.rb:9:in `new'"
# "path/to/foo.rb:9:in `<main>'"
//}...
<< 1 2 3 ... > >>