別のキーワード
種類
- インスタンスメソッド (95)
- クラス (11)
キーワード
- == (11)
- Time (11)
-
backtrace
_ locations (11) - byteoffset (4)
-
deconstruct
_ keys (3) - mon (11)
- offset (22)
- strftime (11)
-
to
_ a (11)
検索結果
先頭5件
-
Time
# month -> Integer (21313.0) -
月を整数で返します。
...月を整数で返します。
//emlist[][ruby]{
t = Time.local(2000,1,2,3,4,5) # => 2000-01-02 03:04:05 +0900
p t.month # => 1
p t.mon # => 1
//}... -
Exception
# backtrace _ locations -> [Thread :: Backtrace :: Location] (15372.0) -
バックトレース情報を返します。Exception#backtraceに似ていますが、 Thread::Backtrace::Location の配列を返す点が異なります。
...Exception#backtraceに似ていますが、
Thread::Backtrace::Location の配列を返す点が異なります。
現状では Exception#set_backtrace によって戻り値が変化する事はあり
ません。
//emlist[例: test.rb][ruby]{
require "date"
def check_long_month(month)
return if......Date.new(2000, month, -1).day == 31
raise "#{month} is not long month"
end
def get_exception
return begin
yield
rescue => e
e
end
end
e = get_exception { check_long_month(2) }
p e.backtrace_locations
# => ["test.rb:4:in `check_long_month'", "test.rb:15:in `block in <main>'", "test.......rb:9:in `get_exception'", "test.rb:15:in `<main>'"]
//}
@see Exception#backtrace... -
Time
# strftime(format) -> String (15272.0) -
時刻を format 文字列に従って文字列に変換した結果を返します。
...(January, February ... )
* %b: 月の省略名(Jan, Feb ... )
* %C: 世紀 (2009年であれば 20)
* %c: 日付と時刻 (%a %b %e %T %Y)
* %D: 日付 (%m/%d/%y)
* %d: 日(01-31)
* %e: 日。一桁の場合、半角空白で埋める ( 1..31)
* %F: %Y-%m-%d と同等 (ISO 8601の日......する
EとOは無視されます。
//emlist[例][ruby]{
p t = Time.new(2001,2,3,4,5,6,"+09:00") # => 2001-02-03 04:05:06 +0900
p t.strftime("Printed on %m/%d/%Y") # => "Printed on 02/03/2001"
p t.strftime("Printed on %m/%-d/%_6Y") # => "Printed on 02/3/ 2001"
p t.strftime("at %I:%M%p")......strftime("%Y%m%d") # => 20010203 Calendar date (basic)
p t.strftime("%F") # => 2001-02-03 Calendar date (extended)
p t.strftime("%Y-%m") # => 2001-02 Calendar date, reduced accuracy, specific month
p t.strftime("%Y"... -
Time (12024.0)
-
時刻を表すクラスです。
...時刻を表すクラスです。
Time.now は現在の時刻を返します。
File.mtime などが返すファイルのタイムスタンプは Time
オブジェクトです。
Time オブジェクトは時刻を起算時からの経過秒数で保持しています。
起算時は協定世界......定するかどうかはシステムに
よります。
Time オブジェクトが格納可能な時刻の範囲は環境によって異なっていましたが、
Ruby 1.9.2 からは OS の制限の影響を受けません。
また、Time オブジェクトは協定世界時と地方時のど......pporo-rubykaigi-02-akr-2009.pdf や
「APIデザインケーススタディ」(https://gihyo.jp/book/2016/978-4-7741-7802-8)
の第4章を参照してください。
localtime(3) も参照してください。
=== C 言語との違いに注意
C 言語の tm 構造体とは異なり、month は 1... -
Time
# deconstruct _ keys(array _ of _ names _ or _ nil) -> Hash (9260.0) -
パターンマッチに使用する名前と値の Hash を返します。
...* :year
* :month
* :day
* :yday
* :wday
* :hour
* :min
* :sec
* :subsec
* :dst
* :zone
@param array_of_names_or_nil パターンマッチに使用する名前の配列を指定します。nil の場合は全てをパターンマッチに使用します。
//emlist[例][ruby]{
t......= Time.utc(2022, 10, 5, 21, 25, 30)
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:
p......rking 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_objec... -
DateTime
# deconstruct _ keys(array _ of _ names _ or _ nil) -> Hash (9248.0) -
パターンマッチに使用する名前と値の Hash を返します。
...* :year
* :month
* :day
* :yday
* :wday
* :hour
* :min
* :sec
* :sec_fraction
* :zone
@param array_of_names_or_nil パターンマッチに使用する名前の配列を指定します。nil の場合は全てをパターンマッチに使用します。
//emlist[例][ruby]{
dt......ateTime.new(2022, 10, 5, 13, 30)
if 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 #......}"
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_... -
MatchData
# offset(name) -> [Integer , Integer] | [nil , nil] (6331.0) -
name という名前付きグループに対応する部分文字列のオフセットの配列 [start, end] を返 します。
...ame という名前付きグループに対応する部分文字列のオフセットの配列 [start, end] を返
します。
//emlist[例][ruby]{
[ self.begin(name), self.end(name) ]
//}
と同じです。nameの名前付きグループにマッチした部分文字列がなければ
[nil, nil]......ame 名前(シンボルか文字列)
@raise IndexError 正規表現中で定義されていない name を指定した場合に発生します。
//emlist[例][ruby]{
/(?<year>\d{4})年(?<month>\d{1,2})月(?:(?<day>\d{1,2})日)?/ =~ "2021年1月"
p $~.offset('year') # => [0, 4]
p $~.offset(:yea......r) # => [0, 4]
p $~.offset('month') # => [5, 6]
p $~.offset(:month) # => [5, 6]
p $~.offset('day') # => [nil, nil]
p $~.offset('century') # => `offset': undefined group name reference: century (IndexError)
//}
@see MatchData#begin, MatchData#end......r) # => [0, 4]
p $~.offset('month') # => [5, 6]
p $~.offset(:month) # => [5, 6]
p $~.offset('day') # => [nil, nil]
p $~.offset('century') # => `offset': undefined group name reference: century (IndexError)
//}
@see MatchData#begin, MatchData#end, MatchData#offset... -
MatchData
# byteoffset(name) -> [Integer , Integer] | [nil , nil] (6324.0) -
name という名前付きグループに対応する部分文字列のバイト単位のオフセットの 配列 [start, end] を返します。
...name という名前付きグループに対応する部分文字列のバイト単位のオフセットの
配列 [start, end] を返します。
nameの名前付きグループにマッチした部分文字列がなければ
[nil, nil] を返します。
@param name 名前(シンボルか文字......ise IndexError 正規表現中で定義されていない name を指定した場合に発生します。
//emlist[例][ruby]{
/(?<year>\d{4})年(?<month>\d{1,2})月(?:(?<day>\d{1,2})日)?/ =~ "2021年1月"
p $~.byteoffset('year') # => [0, 4]
p $~.byteoffset(:year) # => [0, 4]
p $~.byteoffse......t('month') # => [7, 8]
p $~.byteoffset(:month) # => [7, 8]
p $~.byteoffset('day') # => [nil, nil]
p $~.byteoffset('century') # => `offset': undefined group name reference: century (IndexError)
//}
@see MatchData#offset... -
MatchData
# offset(n) -> [Integer , Integer] | [nil , nil] (6311.0) -
n 番目の部分文字列のオフセットの配列 [start, end] を返 します。
...ットの配列 [start, end] を返
します。
//emlist[例][ruby]{
[ self.begin(n), self.end(n) ]
//}
と同じです。n番目の部分文字列がマッチしていなければ
[nil, nil] を返します。
@param n 部分文字列を指定する数値
@raise IndexError 範囲外の n を......指定した場合に発生します。
@see MatchData#begin, MatchData#end......指定した場合に発生します。
@see MatchData#begin, MatchData#end, MatchData#offset... -
MatchData
# byteoffset(n) -> [Integer , Integer] | [nil , nil] (6304.0) -
n 番目の部分文字列のバイト単位のオフセットの 配列 [start, end] を返します。
...のオフセットの
配列 [start, end] を返します。
n番目の部分文字列がマッチしていなければ [nil, nil] を返します。
@param n 部分文字列を指定する数値
@raise IndexError 範囲外の n を指定した場合に発生します。
@see MatchData#offset... -
Date
# deconstruct _ keys(array _ of _ names _ or _ nil) -> Hash (6260.0) -
パターンマッチに使用する名前と値の Hash を返します。
...* :year
* :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 # decon......truct_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... -
Time
# mon -> Integer (6213.0) -
月を整数で返します。
...月を整数で返します。
//emlist[][ruby]{
t = Time.local(2000,1,2,3,4,5) # => 2000-01-02 03:04:05 +0900
p t.month # => 1
p t.mon # => 1
//}... -
Exception
# ==(other) -> bool (6208.0) -
自身と指定された other のクラスが同じであり、 message と backtrace が == メソッドで比較して 等しい場合に true を返します。そうでない場合に false を返します。
...自身と指定された other のクラスが同じであり、
message と backtrace が == メソッドで比較して
等しい場合に true を返します。そうでない場合に false を返します。
@param other 自身と比較したいオブジェクトを指定します。......
Exception#exception を実行して変換を試みます。
//emlist[例][ruby]{
require "date"
def check_long_month(month)
return if Date.new(2000, month, -1).day == 31
raise "#{month} is not long month"
end
def get_exception
return begin
yield
rescue => e
e
end
en......d
results = [2, 2, 4].map { |e | get_exception { check_long_month(e) } }
p results.map { |e| e.class }
# => [RuntimeError, RuntimeError, RuntimeError]
p results.map { |e| e.message }
# => ["2 is not long month", "2 is not long month", "4 is not long month"]
# class, message, backtrace が同一の... -
Time
# to _ a -> Array (6012.0) -
時刻を10要素の配列で返します。
...す。
* sec: 秒 (整数 0-60) (60はうるう秒)
* min: 分 (整数 0-59)
* hour: 時 (整数 0-23)
* mday: 日 (整数)
* mon: 月 (整数 1-12)
* year: 年 (整数 2000年=2000)
* wday: 曜日 (整数 0-6)
* yday: 年内通算日 (整数 1-366)
* isdst: 夏時間......であるかどうか (true/false)
* zone: タイムゾーン (文字列)
//emlist[][ruby]{
t = Time.local(2000,1,2,3,4,5)
p t # => 2000-01-02 03:04:05 +0900
p t.to_a # => [5, 4, 3, 2, 1, 2000, 0, 2, false, "JST"]
//}
要素の順序は C 言語の tm 構造体に合わせています。......ただし、
tm 構造体に zone はありません。
注意: C 言語の tm 構造体とは異なり、month は 1 月に対
して 1 を返し、year は 1998 年に対して 1998 を返します。また、
yday は 1 から数えます。...