26件ヒット
[1-26件を表示]
(0.094秒)
別のキーワード
ライブラリ
- date (14)
-
json
/ add / date (12)
キーワード
- <=> (12)
-
deconstruct
_ keys (2) -
to
_ json (12)
検索結果
先頭3件
-
Date
# <=>(other) -> -1 | 0 | 1 | nil (114.0) -
二つの日付を比較します。 同じ日付なら 0 を、self が other よりあとの日付なら 1 を、 その逆なら -1 を返します。
...で nil を返します。
//emlist[][ruby]{
require "date"
p Date.new(2001, 2, 3) <=> Date.new(2001, 2, 4) # => -1
p Date.new(2001, 2, 3) <=> Date.new(2001, 2, 3) # => 0
p Date.new(2001, 2, 3) <=> Date.new(2001, 2, 2) # => 1
p Date.new(2001, 2, 3) <=> Object.new # => nil
p Date.new(2001......, 2, 3) <=> Rational(4903887, 2) # => 0
//}
@param other 日付オブジェクトまたは数値... -
Date
# deconstruct _ keys(array _ of _ names _ or _ nil) -> Hash (114.0) -
パターンマッチに使用する名前と値の Hash を返します。
...ray_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... -
Date
# to _ json(*args) -> String (114.0) -
自身を JSON 形式の文字列に変換して返します。
...am args 引数はそのまま JSON::Generator::GeneratorMethods::Hash#to_json に渡されます。
//emlist[例][ruby]{
require "json/add/core"
Date.today.to_json
# => "{\"json_class\":\"Date\",\"y\":2018,\"m\":12,\"d\":11,\"sg\":2299161.0}"
//}
@see JSON::Generator::GeneratorMethods::Hash#to_js...