るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

モジュール

検索結果

<< 1 2 3 ... > >>

Module#ruby2_keywords(method_name, ...) -> nil (18463.0)

For the given method names, marks the method as passing keywords through a normal argument splat. This should only be called on methods that accept an argument splat (`*args`) but not explicit keywords or a keyword splat. It marks the method such that if the method is called with keyword arguments, the final hash argument is marked with a special flag such that if it is the final element of a normal argument splat to another method call, and that method call does not include explicit keywords or a keyword splat, the final element is interpreted as keywords. In other words, keywords will be passed through the method to other methods.

...given method names, marks the method as passing keywords through
a normal argument splat. This should only be called on methods that
accept an argument splat (`*args`) but not explicit keywords or a
key
word splat. It marks the method such that if the method is called
with keyword arguments, the fi...
...al hash argument is marked with a special
flag such that if it is the final element of a normal argument splat to
another method call, and that method call does not include explicit
key
words or a keyword splat, the final element is interpreted as
key
words. In other words, keywords will be passed thr...
...ethods.

This should only be used for methods that delegate keywords to another
method, and only for backwards compatibility with Ruby versions before
2.7.

This method will probably be removed at some point, as it exists only
for backwards compatibility. As it does not exist in Ruby versions
before...

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

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

...には
nil を返します。

該当するキーが複数存在する場合、どのキーを返すかは不定です。

Hash#index は 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...

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

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

...hour
* :min
* :sec
* :sec_fraction
* :zone

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

//emlist[例][ruby]{
dt = DateTime.new(2022, 10, 5, 13, 30)

i
f dt in wday: 1....
...our: 10..18 # deconstruct_keys が使われます
puts "Working time"
end
#=> "Working time" が出力される

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

# クラスのチェックと組み合わせて利用することもできます
i
f 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...

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

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

...our
* :min
* :sec
* :subsec
* :dst
* :zone

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

//emlist[例][ruby]{
t = Time.utc(2022, 10, 5, 21, 25, 30)

i
f t in wday: 3,...
...construct_keys が使われます
puts "first Wednesday of the month"
end
#=> "first Wednesday of the month" が出力される

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

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

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

REXML::Element#delete_attribute(key) -> REXML::Attribute | nil (6342.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'/>
//}...

絞り込み条件を変える

Hash#filter! {|key, value| ... } -> self | nil (6328.0)

キーと値を引数としてブロックを評価した結果が真であるような要素を self に残します。

...self
に残します。

keep_if は常に self を返します。
filter! と select! はオブジェクトが変更された場合に self を、
されていない場合に nil を返します。

ブロックが与えられなかった場合は、自身と keep_if から生成した
Enumerator...
.../emlist[例][ruby]{
h1 = {}
c = ("a".."g")
c.each_with_index {|e, i| h1[i] = e }

h2 = h1.dup
h1.select! # => #<Enumerator: {0=>"a", 1=>"b", 2=>"c", 3=>"d", 4=>"e", 5=>"f", 6=>"g"}:select!>

h1.select! { |k, v| k % 3 == 0 } # => {0=>"a", 3=>"d", 6=>"g"}
h1.select! { |k, v| true } # => nil
h...
...2.keep_if { |k, v| k % 3 == 0 } # => {0=>"a", 3=>"d", 6=>"g"}
h2.keep_if { |k, v| true } # => {0=>"a", 3=>"d", 6=>"g"}
//}

@see Hash#select, Hash#delete_if, Hash#reject!...

Hash#delete_if {|key, value| ... } -> self (6287.0)

キーと値を引数としてブロックを評価した結果が真であ るような要素を self から削除します。

...削除します。

delete_if は常に self を返します。
reject! は、要素を削除しなかった場合には nil を返し、
そうでなければ self を返します。

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

//emlist[例][ruby]{
h = { 2 => "8" ,4 => "6" ,...
...h.reject!{|key, value| key.to_i < value.to_i } #=> { 6 => "4", 8 => "2" }
p h #=> { 6 => "4", 8 => "2" }

p h.delete_if{|key, value| key.to_i < value.to_i } #=> { 6 => "4", 8 => "2" }
p h.reject!{|key, value| key.to_i < value.to_i } #=> nil
//}

@se...
...e Hash#reject,Hash#delete
@see Hash#keep_if,Hash#select!...

MatchData#bytebegin(n) -> Integer | nil (6279.0)

n 番目の部分文字列先頭のバイトオフセットを返します。

...のバイトオフセットを返します。

0 はマッチ全体を意味します。
n 番目の部分文字列がマッチしていなければ nilを返します。

引数に文字列またはシンボルを渡した場合は、対応する名前付きキャプチャの先頭のバイトオ...
...指定する文字列またはシンボル。

@raise IndexError 範囲外の n を指定した場合に発生します。
@raise IndexError 正規表現中で定義されていない name を指定した場合に発生します。

//emlist[例][ruby]{
/(c).*(いう).*(e.*)/ =~ 'abcあいうdef'
p...
...egin(0) # => 2
p $~.bytebegin(1) # => 2
p $~.bytebegin(2) # => 6
p $~.bytebegin(3) # => 13
p $~.bytebegin(4) # => index 4 out of matches (IndexError)
//}

//emlist[シンボルを指定する例][ruby]{
/(?<key>\S+):\s*(?<value>\S+)/ =~ "name: ruby"
$~ # => #<MatchData "name: ruby"...

MatchData#bytebegin(name) -> Integer | nil (6279.0)

n 番目の部分文字列先頭のバイトオフセットを返します。

...のバイトオフセットを返します。

0 はマッチ全体を意味します。
n 番目の部分文字列がマッチしていなければ nilを返します。

引数に文字列またはシンボルを渡した場合は、対応する名前付きキャプチャの先頭のバイトオ...
...指定する文字列またはシンボル。

@raise IndexError 範囲外の n を指定した場合に発生します。
@raise IndexError 正規表現中で定義されていない name を指定した場合に発生します。

//emlist[例][ruby]{
/(c).*(いう).*(e.*)/ =~ 'abcあいうdef'
p...
...egin(0) # => 2
p $~.bytebegin(1) # => 2
p $~.bytebegin(2) # => 6
p $~.bytebegin(3) # => 13
p $~.bytebegin(4) # => index 4 out of matches (IndexError)
//}

//emlist[シンボルを指定する例][ruby]{
/(?<key>\S+):\s*(?<value>\S+)/ =~ "name: ruby"
$~ # => #<MatchData "name: ruby"...

JSON::State#indent=(string) (6261.0)

インデントに使用する文字列をセットします。

...ring インデントに使用する文字列を指定します。

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

json_state = JSON::State.new(indent: "\t")
json_state.indent # => "\t"
JSON.generate({key1: "value1", key2: "value2"}, json_state)
# => "{\t\"key1\":\"value1\",\t\"key2\":\"value2\"}"
json_state.i...
...ndent = " "
JSON.generate({key1: "value1", key2: "value2"}, json_state)
# => "{ \"key1\":\"value1\", \"key2\":\"value2\"}"
//}...

絞り込み条件を変える

Hash#include?(key) -> bool (6253.0)

ハッシュが key をキーとして持つ時真を返します。

...ハッシュが key をキーとして持つ時真を返します。

@param key 探索するキーを指定します。

//emlist[][ruby]{
p({1 => "one"}.key?(1)) # => true
p({1 => "one"}.key?(2)) # => false
//}

@see Hash#value?...

Net::HTTPHeader#add_field(key, val) -> () (6248.0)

key ヘッダフィールドに val を追加します。

...
key
ヘッダフィールドに val を追加します。

key
に元々設定されていた値は破棄されず、それに val 追加されます。

@param key ヘッダフィール名を文字列で与えます。
@param val keyで指定したフィールドに追加する文字列を与え...
...et::HTTPHeader#get_fields

//emlist[例][ruby]{
request.add_field 'X-My-Header', 'a'
p request['X-My-Header'] #=> "a"
p request.get_fields('X-My-Header') #=> ["a"]
request.add_field 'X-My-Header', 'b'
p request['X-My-Header'] #=> "a, b"
p request.get_fields('X-My-Header')...
...#=> ["a", "b"]
request.add_field 'X-My-Header', 'c'
p request['X-My-Header'] #=> "a, b, c"
p request.get_fields('X-My-Header') #=> ["a", "b", "c"]
//}...

Net::HTTPHeader#get_fields(key) -> [String] (6242.0)

key ヘッダフィールドの値 (文字列) を配列で返します。

...key ヘッダフィールドの値 (文字列) を配列で返します。

たとえばキー 'content-length' に対しては ['2048'] のような
文字列が得られます。一種類のヘッダフィールドが一つのヘッダの中
に複数存在することがありえます。
key
...
...大文字小文字を区別しません。

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

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

uri = URI.parse('http://www.example.com/index.html')
res = Net::HTTP.get_response(uri)
res.get_fields('accept-ranges') # => ["none"]
//}

@see Net::...
...HTTPHeader#[] , Net::HTTPHeader#[]=,
Net::HTTPHeader#add_field...
<< 1 2 3 ... > >>