ライブラリ
- ビルトイン (167)
クラス
-
Enumerator
:: ArithmeticSequence (6) - Exception (22)
- KeyError (7)
- String (132)
キーワード
- [] (66)
-
backtrace
_ locations (11) - key (7)
- slice (66)
検索結果
先頭5件
-
Exception
# ==(other) -> bool (26141.0) -
自身と指定された other のクラスが同じであり、 message と backtrace が == メソッドで比較して 等しい場合に true を返します。そうでない場合に false を返します。
...自身と指定された other のクラスが同じであり、
message と backtrace が == メソッドで比較して
等しい場合に true を返します。そうでない場合に false を返します。
@param other 自身と比較したいオブジェクトを指定します。......。
//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
end
results = [2, 2, 4].map { |e | get_exception { check_long_month(e)......is not long month", "2 is not long month", "4 is not long month"]
# class, message, backtrace が同一のため true になる
p results[0] == results[1] # => true
# class, backtrace が同一だが、message がことなるため false になる
p results[0] == results[2] # => false
//}... -
Enumerator
:: ArithmeticSequence # ==(other) -> bool (26107.0) -
Enumerable::ArithmeticSequence として等しいか判定します。
...Enumerable::ArithmeticSequence として等しいか判定します。
other が Enumerable::ArithmeticSequence で
begin, end, step, exclude_end? が等しい時に
true を返します。
@param other 自身と比較する Enumerable::ArithmeticSequence... -
Exception
# backtrace _ locations -> [Thread :: Backtrace :: Location] (8013.0) -
バックトレース情報を返します。Exception#backtraceに似ていますが、 Thread::Backtrace::Location の配列を返す点が異なります。
...list[例: 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
#... -
KeyError
# key -> object (8013.0) -
KeyError の原因となったメソッド呼び出しのキーを返します。
...Error キーが設定されていない時に発生します。
例:
h = Hash.new
begin
h.fetch('gumby'*20)
rescue KeyError => e
p e.message # => "key not found: \"gumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbyg..."
p 'gumby'*20 == e.key # => true
end... -
String
# [](nth) -> String | nil (8008.0) -
nth 番目の文字を返します。 nth が負の場合は文字列の末尾から数えます。 つまり、 self.size + nth 番目の文字を返します。
...置を表す整数
@return 指定した位置の文字を表す String オブジェクト
//emlist[例][ruby]{
p 'bar'[2] # => "r"
p 'bar'[2] == ?r # => true
p 'bar'[-1] # => "r"
p 'bar'[3] # => nil
p 'bar'[-4] # => nil
//}
このメソッドの仕様は 1.8.x 以前から大... -
String
# [](regexp , nth = 0) -> String (8008.0) -
正規表現 regexp の nth 番目の括弧にマッチする最初の部分文字列を返します。 nth を省略したときや 0 の場合は正規表現がマッチした部分文字列全体を返します。 正規表現が self にマッチしなかった場合や nth に対応する括弧がないときは nil を返します。
...m regexp 取得したい文字列のパターンを示す正規表現
@param nth 取得したい正規表現レジスタのインデックス。整数
//emlist[例][ruby]{
p "foobar"[/bar/] # => "bar"
p $~.begin(0) # => 3
p "def getcnt(line)"[ /def\s+(\w+)/, 1 ] # => "getcnt"
//}... -
String
# slice(nth) -> String | nil (8008.0) -
nth 番目の文字を返します。 nth が負の場合は文字列の末尾から数えます。 つまり、 self.size + nth 番目の文字を返します。
...置を表す整数
@return 指定した位置の文字を表す String オブジェクト
//emlist[例][ruby]{
p 'bar'[2] # => "r"
p 'bar'[2] == ?r # => true
p 'bar'[-1] # => "r"
p 'bar'[3] # => nil
p 'bar'[-4] # => nil
//}
このメソッドの仕様は 1.8.x 以前から大... -
String
# slice(regexp , nth = 0) -> String (8008.0) -
正規表現 regexp の nth 番目の括弧にマッチする最初の部分文字列を返します。 nth を省略したときや 0 の場合は正規表現がマッチした部分文字列全体を返します。 正規表現が self にマッチしなかった場合や nth に対応する括弧がないときは nil を返します。
...m regexp 取得したい文字列のパターンを示す正規表現
@param nth 取得したい正規表現レジスタのインデックス。整数
//emlist[例][ruby]{
p "foobar"[/bar/] # => "bar"
p $~.begin(0) # => 3
p "def getcnt(line)"[ /def\s+(\w+)/, 1 ] # => "getcnt"
//}... -
String
# [](nth , len) -> String | nil (8003.0) -
nth 文字目から長さ len 文字の部分文字列を新しく作って返します。 nth が負の場合は文字列の末尾から数えます。
nth 文字目から長さ len 文字の部分文字列を新しく作って返します。
nth が負の場合は文字列の末尾から数えます。
@param nth 取得したい文字列の開始インデックスを整数で指定します。
@param len 取得したい文字列の長さを正の整数で指定します。
@return nth が範囲外を指す場合は nil を返します。
//emlist[例][ruby]{
str0 = "bar"
str0[2, 1] #=> "r"
str0[2, 0] #=> ""
str0[2, 100] #=> "r" (右側を超えても... -
String
# [](range) -> String (8003.0) -
rangeで指定したインデックスの範囲に含まれる部分文字列を返します。
...クスの範囲に含まれる部分文字列を返します。
@param range 取得したい文字列の範囲を示す Range オブジェクト
=== rangeオブジェクトが終端を含む場合
インデックスと文字列の対応については以下の対照図も参照してくださ......2] # => ""
'abcd'[ 4 .. 2] # => ""
'abcd'[ 5 .. 2] # => nil
'abcd'[-3 .. 2] # => "bc"
'abcd'[-4 .. 2] # => "abc"
'abcd'[-5 .. 2] # => nil
//}
=== rangeオブジェクトが終端を含まない場合
文字列と「隙間」の関係については以下の模式図を参照してくださ...