126件ヒット
[101-126件を表示]
(0.058秒)
ライブラリ
- ビルトイン (66)
-
rubygems
/ remote _ fetcher (24) -
rubygems
/ spec _ fetcher (24) -
rubygems
/ test _ utilities (12)
クラス
- Data (6)
-
Gem
:: RemoteFetcher (24) -
Gem
:: RemoteFetcher :: FetchError (12) -
Gem
:: SpecFetcher (24) - Hash (24)
オブジェクト
- ENV (36)
検索結果
先頭3件
-
Data
. define(*args) {|subclass| block } -> Class (19.0) -
Data クラスに新しいサブクラスを作って、それを返します。
...Fetcher
Response = Data.define(:body)
NotFound = Data.define
def get(url)
# ダミーの実装
if url == "http://example.com/"
Response.new(body: "Current time is #{Time.now}")
else
NotFound.new
end
end
end
def fetch(url)
fetcher = HTTPFetcher.new
case fetch......er.get(url)
in HTTPFetcher::Response(body)
body
in HTTPFetcher::NotFound
:NotFound
end
end
p fetch("http://example.com/") # => "Current time is 2023-01-10 10:00:53 +0900"
p fetch("http://example.com/404") # => :NotFound
//}
@param args 値オブジェクトのクラスを定義... -
Hash
. new {|hash , key| . . . } -> Hash (7.0) -
空の新しいハッシュを生成します。ブロックの評価結果がデフォルト値になりま す。設定したデフォルト値はHash#default_procで参照できます。
...#=> "foo"
p h[2].object_id #=> 6126840
p h #=> {1=>"foobar", 2=>"foo"}
# 値が設定されていないときに(fetchのように)例外をあげるようにもできる
h = Hash.new {|hash, key|
raise(IndexError, "hash[#{key}] has no value")... -
Hash
. new(ifnone = nil) -> Hash (2.0) -
空の新しいハッシュを生成します。ifnone はキーに対 応する値が存在しない時のデフォルト値です。設定したデフォルト値はHash#defaultで参照できます。
空の新しいハッシュを生成します。ifnone はキーに対
応する値が存在しない時のデフォルト値です。設定したデフォルト値はHash#defaultで参照できます。
ifnoneを省略した Hash.new は {} と同じです。
デフォルト値として、毎回同一のオブジェクトifnoneを返します。
それにより、一箇所のデフォルト値の変更が他の値のデフォルト値にも影響します。
//emlist[][ruby]{
h = Hash.new([])
h[0] << 0
h[1] << 1
p h.default #=> [0, 1]
//}
これを避けるには、破壊的でないメソッドで再代入する...