るりまサーチ

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

別のキーワード

  1. fiddle ruby_free
  2. rbconfig ruby
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

クラス

モジュール

検索結果

<< 1 2 3 ... > >>

Hash#key(val) -> object (18244.0)

値 val に対応するキーを返します。対応する要素が存在しない時には nil を返します。

...obsolete です。
使用すると警告メッセージが表示されます。

@
param val 探索に用いる値を指定します。

//emlist[例][ruby]{
h = {:ab => "some" , :cd => "all" , :ef => "all"}

p h.key("some") #=> :ab
p h.key("all") #=> :cd
p h.key("at") #=> nil
//}

@
see Hash#invert...
...キーが複数存在する場合、どのキーを返すかは不定です。


@
param val 探索に用いる値を指定します。

//emlist[例][ruby]{
h = {:ab => "some" , :cd => "all" , :ef => "all"}

p h.key("some") #=> :ab
p h.key("all") #=> :cd
p h.key("at") #=> nil
//}

@
see Hash#invert...

Struct#deconstruct_keys(array_of_names) -> Hash (15225.0)

self のメンバの名前と値の組を Hash で返します。

...

@
param array_of_names 返り値に含めるメンバの名前の配列を指定します。nil の場合は全てのメンバを意味します。

//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
h = joe.deconstruct_...
...keys([:zip, :address])
h # => {:zip=>12345, :address=>"123 Maple, Anytown NC"}

# 引数が nil の場合は全てのメンバを返します。
h = joe.deconstruct_keys(nil)
h # => {:name=>"Joseph Smith, Jr.", :address=>"123 Maple, Anytown NC", :zip=>12345}
//}

[注意] 本メソッドの記述は...
...Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。

@
see d:spec/pattern_matching#matching_non_primitive_objects...

Hash#transform_keys! {|key| ... } -> self (12344.0)

すべてのキーに対してブロックを呼び出した結果でハッシュのキーを変更します。 値は変化しません。

...

@
param hash 置き換え前のキーから置き換え後のキーへのハッシュを指定します。
@
return transform_keys! は常に self を返します。
ブロックが与えられなかった場合は、Enumerator オブジェクトを
返します。


//emlist[例]...
...[ruby]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys! {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys!(&:to_sym) # => {:a=>1, :b=>2, :c=>3}
h.transform_keys!(a: "a", d: "d") # => {"a"=>1, :b=>2, :c=>3}
h.transform_keys!.with_index {|k, i| "#{k}.#{i}" }...
...# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}

@
see Hash#transform_keys
@
see Hash#transform_values
@
see Hash#transform_values!...

Hash#transform_keys {|key| ... } -> Hash (12338.0)

すべてのキーに対してブロックを呼び出した結果で置き換えたハッシュを返します。 値は変化しません。

...

@
param hash 置き換え前のキーから置き換え後のキーへのハッシュを指定します。

//emlist[例][ruby]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys(a: "a", d: "d") # => {"a"=>1, :b=>2, :c=>3}
h.transform_keys(&:to...
..._s) # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys.with_index {|k, i| "#{k}.#{i}" }
# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}

@
see Hash#transform_keys!
@
see Hash#transform_values
@
see Hash#transform_values!...

Hash#transform_keys! {|key| ... } -> self (12338.0)

すべてのキーに対してブロックを呼び出した結果でハッシュのキーを変更します。 値は変化しません。

...

@
return transform_keys! は常に self を返します。
ブロックが与えられなかった場合は、Enumerator オブジェクトを
返します。


//emlist[例][ruby]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys! {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transfo...
...rm_keys!(&:to_sym) # => {:a=>1, :b=>2, :c=>3}
h.transform_keys!.with_index {|k, i| "#{k}.#{i}" }
# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}

@
see Hash#transform_keys
@
see Hash#transform_values
@
see Hash#transform_values!...

絞り込み条件を変える

Hash#transform_keys {|key| ... } -> Hash (12332.0)

すべてのキーに対してブロックを呼び出した結果で置き換えたハッシュを返します。 値は変化しません。

...t[例][ruby]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys(&:to_s) # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys.with_index {|k, i| "#{k}.#{i}" }
# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}

@
see Hash#t...
...ransform_keys!
@
see Hash#transform_values
@
see Hash#transform_values!...

CSV::Row#deconstruct_keys(keys) -> Hash (12325.0)

パターンマッチに使用するヘッダの名前と値の Hash を返します。

...ーをシンボルに変換する必要があります。

@
param keys パターンマッチに使用するヘッダの名前の配列を指定します。nil の場合は全てをパターンマッチに使用します。

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

row = CSV::Row.new([:header1, :header2,...
.... }
puts "all 2 or more"
in { header1: ...2, header2: 2.., header3: 2.. }
puts "first column is less than 2, and rest columns are 2 or more"
end
#=> "first column is less than 2, and rest columns are 2 or more" が出力される
//}

@
see d:spec/pattern_matching#matching_non_primitive_objects...

Time#deconstruct_keys(array_of_names_or_nil) -> Hash (12249.0)

パターンマッチに使用する名前と値の Hash を返します。

...month
* :day
* :yday
* :wday
* :hour
* :min
* :sec
* :subsec
* :dst
* :zone

@
param array_of_names_or_nil パターンマッチに使用する名前の配列を指定します。nil の場合は全てをパターンマッチに使用します。

//emlist[例][ruby]{
t
= Time.utc(2...
...if t in wday: 3, day: ..7 # deconstruct_keys が使われます
puts "first Wednesday of the month"
end
#=> "first Wednesday of the month" が出力される

case t
in year: ...2022
puts "too old"
in month: ..9
puts "quarter 1-3"
in wday: 1..5, month:
puts "working day in month #{month}"...
...end
#=> "working day in month 10" が出力される

# クラスのチェックと組み合わせて利用することもできます
if t in Time(wday: 3, day: ..7)
puts "first Wednesday of the month"
end
//}

@
see d:spec/pattern_matching#matching_non_primitive_objects...

Hash#transform_keys! -> Enumerator (12244.0)

すべてのキーに対してブロックを呼び出した結果でハッシュのキーを変更します。 値は変化しません。

...

@
param hash 置き換え前のキーから置き換え後のキーへのハッシュを指定します。
@
return transform_keys! は常に self を返します。
ブロックが与えられなかった場合は、Enumerator オブジェクトを
返します。


//emlist[例]...
...[ruby]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys! {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys!(&:to_sym) # => {:a=>1, :b=>2, :c=>3}
h.transform_keys!(a: "a", d: "d") # => {"a"=>1, :b=>2, :c=>3}
h.transform_keys!.with_index {|k, i| "#{k}.#{i}" }...
...# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}

@
see Hash#transform_keys
@
see Hash#transform_values
@
see Hash#transform_values!...

Hash#transform_keys!(hash) -> self (12244.0)

すべてのキーに対してブロックを呼び出した結果でハッシュのキーを変更します。 値は変化しません。

...

@
param hash 置き換え前のキーから置き換え後のキーへのハッシュを指定します。
@
return transform_keys! は常に self を返します。
ブロックが与えられなかった場合は、Enumerator オブジェクトを
返します。


//emlist[例]...
...[ruby]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys! {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys!(&:to_sym) # => {:a=>1, :b=>2, :c=>3}
h.transform_keys!(a: "a", d: "d") # => {"a"=>1, :b=>2, :c=>3}
h.transform_keys!.with_index {|k, i| "#{k}.#{i}" }...
...# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}

@
see Hash#transform_keys
@
see Hash#transform_values
@
see Hash#transform_values!...

絞り込み条件を変える

Data#deconstruct_keys(array_of_names_or_nil) -> Hash (12243.0)

self のメンバの名前と値の組を Hash で返します。

...と値の組を Hash で返します。

//emlist[例][ruby]{
Measure = Data.define(:amount, :unit)

distance = Measure.new(10, 'km')
distance.deconstruct_keys(nil) # => {:amount=>10, :unit=>"km"}
distance.deconstruct_keys([:amount]) # => {:amount=>10}
//}

このメソッドは以下のよう...
...す。

//emlist[例][ruby]{
Measure = Data.define(:amount, :unit)
distance = Measure.new(10, 'km')

case distance
in amount:, unit: 'km' # 裏側で #deconstruct_keys を呼ぶ
puts "It is #{amount} kilometers away"
else
puts "Don't know how to handle it"
end
# "It is 10 kilometers away" が表...
...se distance
in Measure(amount:, unit: 'km')
puts "It is #{amount} kilometers away"
# ...
end
//}

@
param array_of_names_or_nil 返り値に含めるメンバの名前の配列を指定します。nil の場合は全てのメンバを意味します。

[注意] 本メソッドの記述は Data の...

Hash#transform_keys -> Enumerator (12238.0)

すべてのキーに対してブロックを呼び出した結果で置き換えたハッシュを返します。 値は変化しません。

...

@
param hash 置き換え前のキーから置き換え後のキーへのハッシュを指定します。

//emlist[例][ruby]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys(a: "a", d: "d") # => {"a"=>1, :b=>2, :c=>3}
h.transform_keys(&:to...
..._s) # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys.with_index {|k, i| "#{k}.#{i}" }
# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}

@
see Hash#transform_keys!
@
see Hash#transform_values
@
see Hash#transform_values!...

Hash#transform_keys! -> Enumerator (12238.0)

すべてのキーに対してブロックを呼び出した結果でハッシュのキーを変更します。 値は変化しません。

...

@
return transform_keys! は常に self を返します。
ブロックが与えられなかった場合は、Enumerator オブジェクトを
返します。


//emlist[例][ruby]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys! {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transfo...
...rm_keys!(&:to_sym) # => {:a=>1, :b=>2, :c=>3}
h.transform_keys!.with_index {|k, i| "#{k}.#{i}" }
# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}

@
see Hash#transform_keys
@
see Hash#transform_values
@
see Hash#transform_values!...

Hash#transform_keys(hash) -> Hash (12238.0)

すべてのキーに対してブロックを呼び出した結果で置き換えたハッシュを返します。 値は変化しません。

...

@
param hash 置き換え前のキーから置き換え後のキーへのハッシュを指定します。

//emlist[例][ruby]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys(a: "a", d: "d") # => {"a"=>1, :b=>2, :c=>3}
h.transform_keys(&:to...
..._s) # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys.with_index {|k, i| "#{k}.#{i}" }
# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}

@
see Hash#transform_keys!
@
see Hash#transform_values
@
see Hash#transform_values!...

Hash#transform_keys -> Enumerator (12232.0)

すべてのキーに対してブロックを呼び出した結果で置き換えたハッシュを返します。 値は変化しません。

...t[例][ruby]{
h = { a: 1, b: 2, c: 3 }
h.transform_keys {|k| k.to_s } # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys(&:to_s) # => {"a"=>1, "b"=>2, "c"=>3}
h.transform_keys.with_index {|k, i| "#{k}.#{i}" }
# => {"a.0"=>1, "b.1"=>2, "c.2"=>3}
//}

@
see Hash#t...
...ransform_keys!
@
see Hash#transform_values
@
see Hash#transform_values!...

絞り込み条件を変える

Date#deconstruct_keys(array_of_names_or_nil) -> Hash (12225.0)

パターンマッチに使用する名前と値の Hash を返します。

...month
* :day
* :yday
* :wday

@
param array_of_names_or_nil パターンマッチに使用する名前の配列を指定します。nil の場合は全てをパターンマッチに使用します。

//emlist[例][ruby]{
d = Date.new(2022, 10, 5)

if d in wday: 3, day: ..7 # deconstruct_keys...
...使われます
puts "first Wednesday of the month"
end
#=> "first Wednesday of the month" が出力される

case d
in year: ...2022
puts "too old"
in month: ..9
puts "quarter 1-3"
in wday: 1..5, month:
puts "working day in month #{month}"
end
#=> "working day in month 10" が出力され...
...

# クラスのチェックと組み合わせて利用することもできます
if d in Date(wday: 3, day: ..7)
puts "first Wednesday of the month"
end
//}

@
see d:spec/pattern_matching#matching_non_primitive_objects...

DateTime#deconstruct_keys(array_of_names_or_nil) -> Hash (12225.0)

パターンマッチに使用する名前と値の Hash を返します。

...:month
* :day
* :yday
* :wday
* :hour
* :min
* :sec
* :sec_fraction
* :zone

@
param array_of_names_or_nil パターンマッチに使用する名前の配列を指定します。nil の場合は全てをパターンマッチに使用します。

//emlist[例][ruby]{
dt = DateTime.n...
...dt in wday: 1..5, hour: 10..18 # deconstruct_keys が使われます
puts "Working time"
end
#=> "Working time" が出力される

case dt
in year: ...2022
puts "too old"
in month: ..9
puts "quarter 1-3"
in wday: 1..5, month:
puts "working day in month #{month}"
end
#=> "working day in mont...
...h 10" が出力される

# クラスのチェックと組み合わせて利用することもできます
if dt in DateTime(wday: 1..5, hour: 10..18, day: ..7)
puts "Working time, first week of the month"
end
//}

@
see d:spec/pattern_matching#matching_non_primitive_objects...

MatchData#deconstruct_keys(array_of_names) -> Hash (12225.0)

引数で指定された名前の名前付きキャプチャを Hash で返します。

...

@
param array_of_names 名前付きキャプチャの名前の配列を指定します。nil の場合は全ての名前付きキャプチャを意味します。

//emlist[例][ruby]{
m = /(?<hours>\d{2}):(?<minutes>\d{2}):(?<seconds>\d{2})/.match("18:37:22")
m.deconstruct_keys([:hours, :minutes])...
...nutes => "37"}
m.deconstruct_keys(nil) # => {:hours => "18", :minutes => "37", :seconds => "22"}

# 名前付きキャプチャが定義されていなかった場合は空のハッシュを返す
m = /(\d{2}):(\d{2}):(\d{2})/.match("18:37:22")
m.deconstruct_keys(nil) # => {}
//}

@
see d:spec/patter...
...n_matching#matching_non_primitive_objects...

REXML::Element#delete_attribute(key) -> REXML::Attribute | nil (9448.0)

要素から key という属性名の属性を削除します。

... key という属性名の属性を削除します。

削除された属性を返します。

key
という属性名の属性が存在しない場合は削除されずに、nil を返します。

@
param key 削除する要素(文字列(属性名) or REXML::Attributeオブジェクト)

//emlist[]...
...[ruby]{
require 'rexml/document'
e = REXML::Element.new("E")
e.add_attribute("x", "foo"); e # => <E x='foo'/>
e.add_attribute("y:x", "bar"); e # => <E x='foo' y:x='bar'/>
e.delete_attribute("x"); e # => <E y:x='bar'/>
//}...

Net::HTTPHeader#key?(key) -> bool (9271.0)

key というヘッダフィールドがあれば真を返します。 key は大文字小文字を区別しません。

...key というヘッダフィールドがあれば真を返します。
key
は大文字小文字を区別しません。

@
param key 探すヘッダフィールド名を文字列で与えます。

//emlist[例][ruby]{
require 'net/http'

uri = URI.parse('http://www.example.com/index.html')
res = Ne...
...t::HTTP.get_response(uri)
res.key?('content-type') # => true
res.key?('nonexist-header') # => false
//}...

絞り込み条件を変える

Thread#thread_variable_set(key, value) (9236.0)

引数 key で指定した名前のスレッドローカル変数に引数 value をセットしま す。

...引数 key で指定した名前のスレッドローカル変数に引数 value をセットしま
す。

[注意]: Thread#[] でセットしたローカル変数(Fiber ローカル変数)と
異なり、セットした変数は Fiber を切り替えても共通で使える事に注意してく...
...

//emlist[例][ruby]{
t
hr = Thread.new do
T
hread.current.thread_variable_set(:cat, 'meow')
T
hread.current.thread_variable_set("dog", 'woof')
end
t
hr.join # => #<Thread:0x401b3f10 dead>
t
hr.thread_variables # => [:dog, :cat]
//}

@
see Thread#thread_variable_get, Thread#[]...
<< 1 2 3 ... > >>