クラス
- BasicObject (24)
-
CSV
:: Row (3) - Data (3)
- Date (2)
- DateTime (2)
- GDBM (24)
- Hash (62)
-
JSON
:: Parser (12) - KeyError (16)
- Module (12)
- Proc (6)
-
Rake
:: TaskArguments (24) - Thread (12)
- Time (2)
モジュール
- Enumerable (12)
-
Net
:: HTTPHeader (36) - TSort (93)
キーワード
- [] (12)
- chunk (12)
-
deconstruct
_ keys (12) -
default
_ proc= (12) - delete (24)
-
each
_ strongly _ connected _ component (23) -
each
_ strongly _ connected _ component _ from (23) - fetch (36)
-
instance
_ eval (24) - invert (12)
- merge (24)
- parse (12)
- receiver (8)
-
ruby2
_ keywords (18) -
strongly
_ connected _ components (12) -
thread
_ variable _ set (12) -
to
_ h (14) - tsort (12)
-
tsort
_ each (23) -
with
_ defaults (12)
検索結果
先頭5件
-
KeyError
# key -> object (21120.0) -
KeyError の原因となったメソッド呼び出しのキーを返します。
...
KeyError の原因となったメソッド呼び出しのキーを返します。
@raise ArgumentError キーが設定されていない時に発生します。
例:
h = Hash.new
begin
h.fetch('gumby'*20)
rescue KeyError => e
p e.message # => "key not found: \"gumbygumby......gumbygumbygumbygumbygumbygumbygumbygumbygumbygumbyg..."
p 'gumby'*20 == e.key # => true
end... -
CSV
:: Row # deconstruct _ keys(keys) -> Hash (6207.0) -
パターンマッチに使用するヘッダの名前と値の Hash を返します。
...が文字列かつ Hash パターン でパターンマッチしたい場合はキーをシンボルに変換する必要があります。
@param keys パターンマッチに使用するヘッダの名前の配列を指定します。nil の場合は全てをパターンマッチに使用しま......: 2.. }
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_objec... -
Date
# deconstruct _ keys(array _ of _ names _ or _ nil) -> Hash (6119.0) -
パターンマッチに使用する名前と値の Hash を返します。
...: ..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 i......n 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 (6119.0) -
パターンマッチに使用する名前と値の Hash を返します。
...: 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 month 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... -
Time
# deconstruct _ keys(array _ of _ names _ or _ nil) -> Hash (6119.0) -
パターンマッチに使用する名前と値の Hash を返します。
...: ..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 i......n 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... -
Data
# deconstruct _ keys(array _ of _ names _ or _ nil) -> Hash (6113.0) -
self のメンバの名前と値の組を 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}
//}
このメソッドは以下のようにパターンマッチで利用され......construct_keys を呼ぶ
puts "It is #{amount} kilometers away"
else
puts "Don't know how to handle it"
end
# "It is 10 kilometers away" が表示される
# 以下のようにも書ける
case distance
in Measure(amount:, unit: 'km')
puts "It is #{amount} kilometers away"
# ...
end
//}
@par... -
Module
# ruby2 _ keywords(method _ name , . . . ) -> nil (6113.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.
...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 arg......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.
This should only be used for methods that delegate keywords to another
method, and only for backward......aware that if this method is removed, the behavior of the
method will change so that it does not pass through keywords.
//emlist[例][ruby]{
module Mod
def foo(meth, *args, &block)
send(:"do_#{meth}", *args, &block)
end
ruby2_keywords(:foo) if respond_to?(:ruby2_keywords, true)
end
//}... -
Proc
# ruby2 _ keywords -> proc (6113.0) -
Marks the proc as passing keywords through a normal argument splat. This should only be called on procs that accept an argument splat (`*args`) but not explicit keywords or a keyword splat. It marks the proc such that if the proc 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 proc to other methods.
...Marks the proc as passing keywords through a normal argument splat. This
should only be called on procs that accept an argument splat (`*args`)
but not explicit keywords or a keyword splat. It marks the proc such
that if the proc is called with keyword arguments, the final hash
argument is marked......, 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 proc to other methods.
This should only be used for procs that delegate keywords to another
method, and only for backwards......so, be aware that if this method is removed, the behavior of the
proc will change so that it does not pass through keywords.
//emlist[][ruby]{
module Mod
foo = ->(meth, *args, &block) do
send(:"do_#{meth}", *args, &block)
end
foo.ruby2_keywords if foo.respond_to?(:ruby2_keywords)
end
//}... -
KeyError
# receiver -> object (3013.0) -
KeyError の原因となったメソッド呼び出しのレシーバを返します。
...
KeyError の原因となったメソッド呼び出しのレシーバを返します。
@raise ArgumentError レシーバが設定されていない時に発生します。
例:
h = Hash.new
begin
h.fetch('gumby'*20)
rescue KeyError => e
p e.message # => "key not found:......\"gumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbyg..."
p h.equal?(e.receiver) # => true
end... -
GDBM
# delete(key) {|key| . . . } -> object (232.0) -
与えられた key に対応する項目を削除します。
...与えられた key に対応する項目を削除します。
@param key キーを指定します。
@return 指定したキーが存在する場合は、キーに対応する値を返します。
指定したキーが存在しない場合は、 nil を返します。
また、......評価した結果を返します。
require 'gdbm'
GDBM.open("a.db") do |db|
db['a'] = "aaa"
db['d'] = "ddd"
db.delete("a") # => "aaa"
db.delete("b") # => nil
db.delete("c"){|k| "c is missing" } # => "c is missing"
db.delete("d"){|k| "d is missing" } # => "ddd"
end... -
Net
:: HTTPHeader # fetch(key) -> String (180.0) -
key ヘッダフィールドを返します。
...key ヘッダフィールドを返します。
たとえばキー 'content-length' に対しては '2048'
のような文字列が得られます。キーが存在しなければ nil を返します。
該当するキーが登録されてい
ない時には、引数 default が与えられてい......つのヘッダの中に複数存在する
場合にはそれを全て ", " で連結した文字列を返します。
key は大文字小文字を区別しません。
@param key ヘッダフィール名を文字列で与えます。
@param default 該当するキーが登録されていない時......生します。
//emlist[例 key のみ指定。key が存在する][ruby]{
require 'net/http'
uri = URI.parse('http://www.example.com/index.html')
req = Net::HTTP::Get.new(uri.request_uri)
req.fetch("user-agent") # => "Ruby"
//}
//emlist[例 key のみ指定。key が存在しない][ruby]{
requ... -
Net
:: HTTPHeader # fetch(key) {|hash| . . . . } -> String (180.0) -
key ヘッダフィールドを返します。
...key ヘッダフィールドを返します。
たとえばキー 'content-length' に対しては '2048'
のような文字列が得られます。キーが存在しなければ nil を返します。
該当するキーが登録されてい
ない時には、引数 default が与えられてい......つのヘッダの中に複数存在する
場合にはそれを全て ", " で連結した文字列を返します。
key は大文字小文字を区別しません。
@param key ヘッダフィール名を文字列で与えます。
@param default 該当するキーが登録されていない時......生します。
//emlist[例 key のみ指定。key が存在する][ruby]{
require 'net/http'
uri = URI.parse('http://www.example.com/index.html')
req = Net::HTTP::Get.new(uri.request_uri)
req.fetch("user-agent") # => "Ruby"
//}
//emlist[例 key のみ指定。key が存在しない][ruby]{
requ... -
Net
:: HTTPHeader # fetch(key , default) -> String (180.0) -
key ヘッダフィールドを返します。
...key ヘッダフィールドを返します。
たとえばキー 'content-length' に対しては '2048'
のような文字列が得られます。キーが存在しなければ nil を返します。
該当するキーが登録されてい
ない時には、引数 default が与えられてい......つのヘッダの中に複数存在する
場合にはそれを全て ", " で連結した文字列を返します。
key は大文字小文字を区別しません。
@param key ヘッダフィール名を文字列で与えます。
@param default 該当するキーが登録されていない時......生します。
//emlist[例 key のみ指定。key が存在する][ruby]{
require 'net/http'
uri = URI.parse('http://www.example.com/index.html')
req = Net::HTTP::Get.new(uri.request_uri)
req.fetch("user-agent") # => "Ruby"
//}
//emlist[例 key のみ指定。key が存在しない][ruby]{
requ... -
GDBM
# delete(key) -> object | nil (132.0) -
与えられた key に対応する項目を削除します。
...与えられた key に対応する項目を削除します。
@param key キーを指定します。
@return 指定したキーが存在する場合は、キーに対応する値を返します。
指定したキーが存在しない場合は、 nil を返します。
また、......評価した結果を返します。
require 'gdbm'
GDBM.open("a.db") do |db|
db['a'] = "aaa"
db['d'] = "ddd"
db.delete("a") # => "aaa"
db.delete("b") # => nil
db.delete("c"){|k| "c is missing" } # => "c is missing"
db.delete("d"){|k| "d is missing" } # => "ddd"
end...