別のキーワード
検索結果
-
Enumerator
# feed(obj) -> nil (18207.0) -
Enumerator 内部の yield が返す値を設定します。
...# (2) blocks
p x # (5) => "foo"
x = yield # (6) blocks
p x # (8) => nil
x = yield # (9) blocks
p x # not reached w/o another e.next
end
e = o.to_enum
e.next # (1)
e.feed "foo" # (3)
e.next # (4... -
正規表現 (492.0)
-
正規表現 * metachar * expansion * char * anychar * string * str * quantifier * capture * grouping * subexp * selector * anchor * cond * option * encoding * comment * free_format_mode * absenceop * list * specialvar * references
...京都") # => #<MatchData "東京都">
//}
埋め込んだ文字列にメタ文字が含まれているならば、それは
メタ文字として認識されます。
//emlist[][ruby]{
number = "(\\d+)"
operator = "(\\+|-|\\*|/)"
/#{number}#{operator}#{number}/.match("43+291")
# => #<MatchData "......43+291" 1:"43" 2:"+" 3:"291">
//}
埋め込む文字列をリテラルとして認識させたい場合は Regexp.quote を
使います。
===[a:char] 文字
正規表現内では、「\」の後に文字列を置くことで、
ある特定の文字を表現することができます。
これ......帰 return (0x0D)
\b バックスペース back space (0x08)
\f 改ページ form feed (0x0C)
\a ベル bell (0x07)
\e エスケープ文字 escape (0x1B)
\nnn... -
制御構造 (24.0)
-
制御構造 条件分岐: * if * unless * case 繰り返し: * while * until * for * break * next * redo * retry 例外処理: * raise * begin その他: * return * BEGIN * END
...めとする制御構造をクラス設計者が定義する事が出来るものです.
=== 条件分岐
====[a:if] if
//emlist[例][ruby]{
if age >= 12 then
print "adult fee\n"
else
print "child fee\n"
end
gender = if foo.gender == "male" then "male" else "female" end
//}
文法:......結果を返します。
条件が成立しなければ nil を返します。
====[a:unless] unless
//emlist[例][ruby]{
unless baby?
feed_meat
else
feed_milk
end
//}
文法:
unless 式 [then]
式 ...
[else
式 ... ]
end
unless は if......り強力なパターンマッチ構文を提供しています。
//emlist[][ruby]{
case {a: 1, b: 2, c: 3}
in a: Integer => m
"matched: #{m}"
else
"not matched"
end
# => "matched: 1"
//}
パターンマッチ構文についてはspec/pattern_matchingで説明しています。
=== 繰り返...