66件ヒット
[1-66件を表示]
(0.035秒)
種類
- インスタンスメソッド (44)
- モジュール関数 (22)
クラス
-
ObjectSpace
:: WeakMap (22)
モジュール
- Enumerable (22)
- Kernel (22)
キーワード
- []= (11)
-
caller
_ locations (22) -
sort
_ by (22)
検索結果
先頭5件
-
ObjectSpace
:: WeakMap # [](key) -> object | nil (21102.0) -
引数 key で指定されたオブジェクトが参照するオブジェクトを返します。
引数 key で指定されたオブジェクトが参照するオブジェクトを返します。
参照先のオブジェクトが存在しない場合、GC されている場合、対象外のオブジェ
クトを参照している場合に nil を返します。
@param key 参照元のオブジェクトを指定します。 -
ObjectSpace
:: WeakMap # []=(key , value) (9120.0) -
引数 key から引数 value への参照を作成します。
...lue への参照を作成します。
@param key 参照元のオブジェクトを指定します。
@param value 参照先のオブジェクトを指定します。
//emlist[例][ruby]{
weak_map = ObjectSpace::WeakMap.new
key = "text"
weak_map[key] = "test" # => test
weak_map[key] # => test
//}... -
Enumerable
# sort _ by -> Enumerator (20.0) -
ブロックの評価結果を <=> メソッドで比較することで、self を昇 順にソートします。ソートされた配列を新たに生成して返します。
...つまり、以下とほぼ同じ動作をします。
//emlist[例][ruby]{
class Array
def sort_by
self.map {|i| [yield(i), i] }.
sort {|a, b| a[0] <=> b[0] }.
map {|i| i[1]}
end
end
//}
Enumerable#sort と比較して sort_by が優れている点として、
比較条件......。
//emlist[][ruby]{
p ["BAR", "FOO", "bar", "foo"].sort {|a, b| a.downcase <=> b.downcase }
//}
一方、次のように sort_by を使うと downcase の実行回数は要素数と同じです。
つまり、その部分の実行時間は O(n) のオーダーです。
//emlist[][ruby]{
p ["BAR......_by {|v| v.downcase }
//}
以下の、実行回数の検証結果を参照してみてください。
//emlist[][ruby]{
class Integer
def count
$n += 1
self
end
end
ary = []
1.upto(1000) {|v| ary << rand(v) }
$n = 0
ary.sort {|a,b| a.count <=> b.count }
p $n # => 18200
$n =... -
Enumerable
# sort _ by {|item| . . . } -> [object] (20.0) -
ブロックの評価結果を <=> メソッドで比較することで、self を昇 順にソートします。ソートされた配列を新たに生成して返します。
...つまり、以下とほぼ同じ動作をします。
//emlist[例][ruby]{
class Array
def sort_by
self.map {|i| [yield(i), i] }.
sort {|a, b| a[0] <=> b[0] }.
map {|i| i[1]}
end
end
//}
Enumerable#sort と比較して sort_by が優れている点として、
比較条件......。
//emlist[][ruby]{
p ["BAR", "FOO", "bar", "foo"].sort {|a, b| a.downcase <=> b.downcase }
//}
一方、次のように sort_by を使うと downcase の実行回数は要素数と同じです。
つまり、その部分の実行時間は O(n) のオーダーです。
//emlist[][ruby]{
p ["BAR......_by {|v| v.downcase }
//}
以下の、実行回数の検証結果を参照してみてください。
//emlist[][ruby]{
class Integer
def count
$n += 1
self
end
end
ary = []
1.upto(1000) {|v| ary << rand(v) }
$n = 0
ary.sort {|a,b| a.count <=> b.count }
p $n # => 18200
$n =... -
Kernel
. # caller _ locations(range) -> [Thread :: Backtrace :: Location] | nil (20.0) -
現在のフレームを Thread::Backtrace::Location の配列で返します。引 数で指定した値が範囲外の場合は nil を返します。
...= 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 # => []
test3(1, nil)
# => ["/Users/user/test.rb:9:in `test2'", "/Use... -
Kernel
. # caller _ locations(start = 1 , length = nil) -> [Thread :: Backtrace :: Location] | nil (20.0) -
現在のフレームを Thread::Backtrace::Location の配列で返します。引 数で指定した値が範囲外の場合は nil を返します。
...= 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 # => []
test3(1, nil)
# => ["/Users/user/test.rb:9:in `test2'", "/Use...