別のキーワード
種類
- インスタンスメソッド (190)
- 特異メソッド (169)
- モジュール関数 (22)
- クラス (11)
クラス
モジュール
- Kernel (22)
キーワード
- % (11)
- Numeric (11)
- [] (1)
-
default
_ proc= (11) - format (11)
-
handle
_ interrupt (11) - invert (11)
-
is
_ a? (11) - key (7)
-
kind
_ of? (11) - merge (22)
- new (3)
- popen (154)
-
primitive
_ convert (44) - receiver (7)
- replace (11)
-
ruby2
_ keywords (5) - sprintf (11)
-
to
_ h (17) -
to
_ hash (11)
検索結果
先頭5件
-
Range
# hash -> Integer (18143.0) -
始端と終端のハッシュ値と Range#exclude_end? の値からハッシュ値を計算して整数として返します。
...始端と終端のハッシュ値と Range#exclude_end? の値からハッシュ値を計算して整数として返します。
//emlist[例][ruby]{
p (1..2).hash # => 5646
p (1...2).hash # => 16782863
//}... -
Hash
# default _ proc=(pr) (15298.0) -
ハッシュのデフォルト値を返す Proc オブジェクトを 変更します。
...ハッシュのデフォルト値を返す Proc オブジェクトを
変更します。
以前のデフォルトは値(Hash#default)の場合も
Proc の場合(Hash#default_proc)でも上書きされます。
引数には to_proc で Proc オブジェクトに変換できる
オブジェクト......け付けます。
nil を指定した場合は現在の Hash#default_proc をクリアします。
@param pr デフォルト値を返す手続きオブジェクト
//emlist[例][ruby]{
h = {}
h.default_proc = proc do |hash, key|
hash[key] = case
when (key % 15).zero?......else
key
end
end
p h[1] # => 1
p h[2] # => 2
p h[3] # => "Fizz"
p h[5] # => "Buzz"
p h[15] # => "FizzBuzz"
h.default_proc = nil
p h[16] # => nil
# default_proc が nil になったので `16=>16 が追加されていない`
p h # => {1=>1, 2=>2, 3=>"Fiz... -
Hash
# replace(other) -> self (15180.0) -
ハッシュの内容を other の内容で置き換えます。
...ます。
otherがハッシュではない場合、otherのメソッドto_hashを使って暗黙の変換を試みます。
self = other.to_hash.dup と同じです。
@param other ハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return self......{2 => 'B', 3 => 'C'}
foo.replace(bar)
p foo #=> {2=>"B", 3=>"C"}
zoo = {}
zoo = bar.dup
p zoo #=> {2=>"B", 3=>"C"}
class Foo
def to_hash
{:japan => 'kyoto'}
end
end
h = Hash.new
h.replace(Foo.new) #暗黙の変換
p h #=> {:japan=>"kyoto"}
//}
@see Hash#dup,Hash#merge,Object#to_hash... -
Hash
# to _ h -> self | Hash (9244.0) -
self を返します。Hash クラスのサブクラスから呼び出した場合は self を Hash オブジェクトに変換します。
...す。Hash クラスのサブクラスから呼び出した場合は
self を Hash オブジェクトに変換します。
//emlist[例][ruby]{
hash = {}
p hash.to_h # => {}
p hash.to_h == hash # => true
class MyHash < Hash;end
my_hash = MyHash.new
p my_hash.to_h # => {}
p my_hash.clas......s # => MyHash
p my_hash.to_h.class # => Hash
//}
ブロックを指定すると各ペアでブロックを呼び出し、
その結果をペアとして使います。
//emlist[ブロック付きの例][ruby]{
hash = { "a" => 97, "b" => 98 }
hash.to_h {|key, value| [key.upcase, value-32] } #......=> {"A"=>65, "B"=>66}
//}
@see Enumerable#map... -
Hash
# to _ h {|key , value| block } -> Hash (9244.0) -
self を返します。Hash クラスのサブクラスから呼び出した場合は self を Hash オブジェクトに変換します。
...す。Hash クラスのサブクラスから呼び出した場合は
self を Hash オブジェクトに変換します。
//emlist[例][ruby]{
hash = {}
p hash.to_h # => {}
p hash.to_h == hash # => true
class MyHash < Hash;end
my_hash = MyHash.new
p my_hash.to_h # => {}
p my_hash.clas......s # => MyHash
p my_hash.to_h.class # => Hash
//}
ブロックを指定すると各ペアでブロックを呼び出し、
その結果をペアとして使います。
//emlist[ブロック付きの例][ruby]{
hash = { "a" => 97, "b" => 98 }
hash.to_h {|key, value| [key.upcase, value-32] } #......=> {"A"=>65, "B"=>66}
//}
@see Enumerable#map... -
Hash
# to _ h -> self | Hash (9231.0) -
self を返します。Hash クラスのサブクラスから呼び出した場合は self を Hash オブジェクトに変換します。
...す。Hash クラスのサブクラスから呼び出した場合は
self を Hash オブジェクトに変換します。
//emlist[例][ruby]{
hash = {}
p hash.to_h # => {}
p hash.to_h == hash # => true
class MyHash < Hash;end
my_hash = MyHash.new
p my_hash.to_h # => {}
p my_hash.clas......s # => MyHash
p my_hash.to_h.class # => Hash
//}... -
Hash
# merge(*others) -> Hash (9176.0) -
selfとothersのハッシュの内容を順番にマージ(統合)した結果を返します。 デフォルト値はselfの設定のままです。
...値を使います。
othersがハッシュではない場合、othersのメソッドto_hashを使って暗黙の変換を試みます。
@param others マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マージした結......=> 'c'}
bar = {2 => 'B', 3 => 'C', 4 => 'D'}
p foo.merge(bar)
# => {1=>"a", 2=>"B", 3=>"C", 4=>"D"}
p foo # => {1=>"a", 2=>"b", 3=>"c"}
p foo.merge!(bar) {|key, foo_val, bar_val| foo_val + bar_val }
# => {1=>"a", 2=>"bB", 3=>"cC", 4=>"D"}
p foo # => {1=>"a", 2=>"bB", 3=>"cC", 4=>"D......_hash
{:Australia => 'Sydney',
:France => 'Paris'
}
end
end
h = {:Germany => 'Berlin',
:Australia => 'Canberra',
:France => 'Paris'
}
# 暗黙の変換
p h.merge(Foo.new) # => {:Germany=>"Berlin", :Australia=>"Sydney", :France=>"Paris"}
//}
@see Hash#update,Hash#rep... -
Hash
# merge(*others) {|key , self _ val , other _ val| . . . } -> Hash (9176.0) -
selfとothersのハッシュの内容を順番にマージ(統合)した結果を返します。 デフォルト値はselfの設定のままです。
...値を使います。
othersがハッシュではない場合、othersのメソッドto_hashを使って暗黙の変換を試みます。
@param others マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マージした結......=> 'c'}
bar = {2 => 'B', 3 => 'C', 4 => 'D'}
p foo.merge(bar)
# => {1=>"a", 2=>"B", 3=>"C", 4=>"D"}
p foo # => {1=>"a", 2=>"b", 3=>"c"}
p foo.merge!(bar) {|key, foo_val, bar_val| foo_val + bar_val }
# => {1=>"a", 2=>"bB", 3=>"cC", 4=>"D"}
p foo # => {1=>"a", 2=>"bB", 3=>"cC", 4=>"D......_hash
{:Australia => 'Sydney',
:France => 'Paris'
}
end
end
h = {:Germany => 'Berlin',
:Australia => 'Canberra',
:France => 'Paris'
}
# 暗黙の変換
p h.merge(Foo.new) # => {:Germany=>"Berlin", :Australia=>"Sydney", :France=>"Paris"}
//}
@see Hash#update,Hash#rep... -
Hash
# merge(other) -> Hash (9176.0) -
selfとotherのハッシュの内容をマージ(統合)した結果を返します。デフォルト値はselfの設定のままです。
...の値を使います。
otherがハッシュではない場合、otherのメソッドto_hashを使って暗黙の変換を試みます。
@param other マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マージした結......=> 'c'}
bar = {2 => 'B', 3 => 'C', 4 => 'D'}
p foo.merge(bar)
# => {1=>"a", 2=>"B", 3=>"C", 4=>"D"}
p foo # => {1=>"a", 2=>"b", 3=>"c"}
p foo.merge!(bar) {|key, foo_val, bar_val| foo_val + bar_val }
# => {1=>"a", 2=>"bB", 3=>"cC", 4=>"D"}
p foo # => {1=>"a", 2=>"bB", 3=>"cC", 4=>"D......_hash
{:Australia => 'Sydney',
:France => 'Paris'
}
end
end
h = {:Germany => 'Berlin',
:Australia => 'Canberra',
:France => 'Paris'
}
# 暗黙の変換
p h.merge(Foo.new) # => {:Germany=>"Berlin", :Australia=>"Sydney", :France=>"Paris"}
//}
@see Hash#update,Hash#rep... -
Hash
# merge(other) {|key , self _ val , other _ val| . . . } -> Hash (9176.0) -
selfとotherのハッシュの内容をマージ(統合)した結果を返します。デフォルト値はselfの設定のままです。
...の値を使います。
otherがハッシュではない場合、otherのメソッドto_hashを使って暗黙の変換を試みます。
@param other マージ用のハッシュまたはメソッド to_hash でハッシュに変換できるオブジェクトです。
@return マージした結......=> 'c'}
bar = {2 => 'B', 3 => 'C', 4 => 'D'}
p foo.merge(bar)
# => {1=>"a", 2=>"B", 3=>"C", 4=>"D"}
p foo # => {1=>"a", 2=>"b", 3=>"c"}
p foo.merge!(bar) {|key, foo_val, bar_val| foo_val + bar_val }
# => {1=>"a", 2=>"bB", 3=>"cC", 4=>"D"}
p foo # => {1=>"a", 2=>"bB", 3=>"cC", 4=>"D......_hash
{:Australia => 'Sydney',
:France => 'Paris'
}
end
end
h = {:Germany => 'Berlin',
:Australia => 'Canberra',
:France => 'Paris'
}
# 暗黙の変換
p h.merge(Foo.new) # => {:Germany=>"Berlin", :Australia=>"Sydney", :France=>"Paris"}
//}
@see Hash#update,Hash#rep... -
Hash
# invert -> Hash (9151.0) -
値からキーへのハッシュを作成して返します。
...}
p h.invert #=> {0=>"a", 100=>"b", 200=>"c", 300=>"e"}
//}
=== 参考
値が重複していたときに備えて、変換後の値を配列として保持するには、次のようにします。
//emlist[][ruby]{
def safe_invert(orig_hash)
orig_hash.each_key.group_by do |key|
orig_hash[......key]
end
end
p safe_invert({"a"=>1, "b"=>1, "c"=>3}) # => {1=>["a", "b"], 3=>["c"]}
//}
@see Hash#key... -
Object
# to _ hash -> Hash (6244.0) -
オブジェクトの Hash への暗黙の変換が必要なときに内部で呼ばれます。 デフォルトでは定義されていません。
...オブジェクトの Hash への暗黙の変換が必要なときに内部で呼ばれます。
デフォルトでは定義されていません。
説明のためここに記載してありますが、
このメソッドは実際には Object クラスには定義されていません。
必要......すべての場面で代置可能であるような、
* ハッシュそのものとみなせるようなもの
という厳しいものになっています。
//emlist[][ruby]{
class Foo
def to_hash
{'as' => 24}
end
end
it = Foo.new
p({:as => 12}.merge(it)) #=> {"as"=>24, :as=>12}
//}... -
Thread
. handle _ interrupt(hash) { . . . } -> object (6233.0) -
スレッドの割り込みのタイミングを引数で指定した内容に変更してブロックを 実行します。
...Signal.#trap(未サポート)、メインスレッドの終了
(メインスレッドが終了すると、他のスレッドも終了されます)を意味します。
@param hash 例外クラスがキー、割り込みのタイミングを指定する
Symbol が値の Hash を指定し......に含まれます。
また、マスクされた非同期割り込みは再度有効にされるまで延期されます。本
メソッドは sigprocmask(3) に似ています。
@return ブロックの評価結果を返します。
@raise ArgumentError ブロックを指定しなかった場......le_interrupt(RuntimeError => :never) {
begin
# 安全にリソースの割り当てが可能
Thread.handle_interrupt(RuntimeError => :immediate) {
# ...
}
ensure
# 安全にリソースの解放が可能
end
}
end
Thread.pass
# .....