別のキーワード
キーワード
- Marshal フォーマット (12)
- Rubyで使われる記号の意味(正規表現の複雑な記号は除く) (12)
- Rubyの起動 (12)
- pack テンプレート文字列 (12)
-
ruby 1
. 6 feature (12) -
ruby 1
. 8 . 4 feature (12) - パターンマッチ (12)
- プログラム・文・式 (12)
- 正規表現 (12)
- 演算子式 (12)
検索結果
-
正規表現 (97.0)
-
正規表現 * metachar * expansion * char * anychar * string * str * quantifier * capture * grouping * subexp * selector * anchor * cond * option * encoding * comment * free_format_mode * absenceop * list * specialvar * references
...きます。
文字クラスの [ の直後の文字がキャレット(^)である場合、列挙「されていない」
文字にマッチするようになります(これは否定文字クラスと呼ばれます)。
[^a-d]
はabcd以外の1文字にマッチします。
文字クラス内......意味を持ちます。
//emlist[][ruby]{
/[a-z[0-9]]/.match("y") # => #<MatchData "y">
/[a-z[0-9]]/.match("[") # => nil
r = /[a-w&&[^c-g]e]/ # ([a-w] かつ ([^c-g] もしくは e)) つまり [abeh-w] と同じ
r.match("b") # => #<MatchData "b">
r.match("c") # => nil
r.match("e") # => #<MatchData......r.match("w") # => #<MatchData "w">
r.match("z") # => nil
//}
文字クラスでは、否定(^)範囲(-)共通部分(&&)列挙(並べる)という
演算が可能ですが、これらは - > (列挙) > && > ^ という順の結合強度を持ちます。
文字クラス内の3つのメタ文字を... -
パターンマッチ (43.0)
-
パターンマッチ * patterns * variable_binding * variable_pinning * matching_non_primitive_objects * guard_clauses * current_feature_status * pattern_syntax * some_undefined_behavior_examples
...ターンの部品として利用するよ」ということを伝えるためにピン演算子 『^』 を利用することができます。
//emlist[][ruby]{
expectation = 18
case [1, 2]
in ^expectation, *rest
"matched. expectation was: #{expectation}"
else
"not matched. expectation was: #......{id:, level: ^school}] # select the last school, level should match
"matched. school: #{id}"
else
"not matched"
end
#=> "matched. school: 2"
case john # 指定された school の level は "high" だが、最後の school はマッチしない
in school:, schools: [*, {id:, level: ^school}]......var = 2
@@cvar = 3
case [1, 2, 3]
in ^$gvar, ^@ivar, ^@@cvar
"matched"
else
"not matched"
end
#=> "matched"
end
//}
また、括弧を使って任意の式に対してピン演算子を利用できます
//emlist{
a = 1
b = 2
case 3
in ^(a + b)
"matched"
else
"not matched"... -
ruby 1
. 6 feature (31.0) -
ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。
....7 (2002-03-01) [i586-linux]
#<MatchData:0x401b1be4>
-:3: wrong argument type nil (expected Match) (TypeError)
^^^^^ MatchData の間違い
=> ruby 1.6.7 (2002-04-04) [i586-linux]
#<MatchData:0x401b1c98>
nil
: 2002-03-25......03-19) [i586-linux]
"表"
#! ruby -Ks
p %[評価]
=> -:2: parse error
p %[評価]
^
ruby 1.6.7 (2002-03-15) [i586-linux]
=> ruby 1.6.7 (2002-03-19) [i586-linux]
"評価"
: 2002-03-16 $~......ました。
p %q1..1
=> ruby 1.6.5 (2001-10-10) [i586-linux]
".."
=> -:1: unknown type of %string
p %q1..1
^
ruby 1.6.5 (2001-10-15) [i586-linux]
: String#=~
String#=~ の呼出で両辺ともリテラルであったときに速度重視... -
パターンマッチ (25.0)
-
パターンマッチ * patterns * variable_binding * variable_pinning * matching_non_primitive_objects * guard_clauses * current_feature_status * pattern_syntax * some_undefined_behavior_examples
...ターンの部品として利用するよ」ということを伝えるためにピン演算子 『^』 を利用することができます。
//emlist[][ruby]{
expectation = 18
case [1, 2]
in ^expectation, *rest
"matched. expectation was: #{expectation}"
else
"not matched. expectation was: #......{id:, level: ^school}] # select the last school, level should match
"matched. school: #{id}"
else
"not matched"
end
#=> "matched. school: 2"
case john # 指定された school の level は "high" だが、最後の school はマッチしない
in school:, schools: [*, {id:, level: ^school}]......e_pattern
| as_pattern
| array_pattern
| hash_pattern
value_pattern: literal
| Constant
| ^variable
variable_pattern: variable
alternative_pattern: pattern | pattern | ...
as_pattern: pattern => variable
array_pattern: [pattern,......pattern
| array_pattern
| find_pattern
| hash_pattern
value_pattern: literal
| Constant
| ^variable
variable_pattern: variable
alternative_pattern: pattern | pattern | ...
as_pattern: pattern => variable
array_pattern: [pattern,... -
Rubyで使われる記号の意味(正規表現の複雑な記号は除く) (13.0)
-
Rubyで使われる記号の意味(正規表現の複雑な記号は除く) ex q num per and or plus minus ast slash hat sq period comma langl rangl eq tilde dollar at under lbrarbra lbra2rbra2 lbra3rbra3 dq colon ac backslash semicolon
...味する
===[a:hat] ^
: true ^ true
「xor」演算子。排他的論理和。または類似のメソッド。
: a ^= true
「^」演算子の自己代入演算子。aの論理値の反転。
//emlist{
p(a=true);p(a^=true);p(a^=true) #=> true false true
//}
: /^xxx/
正規表現で......を含まない Range オブジェクトを作る範囲演算子です。
全体で範囲式といいます。d:spec/operator#range。
: if /^begin/ .. /^end/ など 条件式 式 .. 式
条件式中の範囲式は特別にフリップフロップのように働きます。
//emlist{
'12345......"some",:ok]
配列のリテラル
: 'abcde'[1,2]
[]メソッドの実行
//emlist{
class String
def [](*a)
'(^^;'
end
end
p( 'abcde'[1,2] ) #=> "(^^;"
//}
: /xx[abc]/
正規表現の文字クラス指定。
===[a:lbra3] (
===[a:rbra3] )
: (true and false)
: p({})
丸... -
Rubyの起動 (13.0)
-
Rubyの起動 * cmd_option * shebang
...まり, "ruby"という文字列を含む行までを
読み飛ばします。スクリプトの終りはEOF(ファイル
の終り), ^D(コントロールD), ^Z(コ
ントロールZ)または予約語__END__で指定されます。
ディレクトリ名を指定すると、スクリプト... -
演算子式 (13.0)
-
演算子式 * assign * selfassign * multiassign * range * range_cond * and * or * not * cond
...**
-(単項)
* / %
+ -
<< >>
&
| ^
> >= < <=
<=> == === != =~ !~
&&
||
.. .........算子(メソッド)
+@, -@ は単項演算子 +, - を表しメソッド定義
などではこの記法を利用します。
//emlist{
| ^ & <=> == === =~ > >= < <= << >>
+ - * / % ** ~ +@ -@ [] []= ` ! != !~
//}
これらの演算子式の定義方......れか
op は以下のいずれかです。演算子と=の間にスペースを
空けてはいけません。
+, -, *, /, %, **, &, |, ^, <<, >>, &&, ||
この形式の代入は
式1 = 式1 op 式2
と評価されます。ただし、op が &&, || の場合には、
式1 o... -
Marshal フォーマット (7.0)
-
Marshal フォーマット フォーマットバージョン 4.8 を元に記述しています。
...| n1) &
(0xffff00ff | n2 * 0x100) &
(0xff00ffff | n3 * 0x10000) &
(0x00ffffff | n4 * 0x1000000)
# p "%x" % n
n = -((n ^ 0xffff_ffff) + 1) if len < 0
n
end
p Marshal.dump(-125).unpack("x2 acC*") # => ["i", -1, 131]
p foo(-1, 131) # => -125......Array # (or String, Regexp, Hash)
end
p Marshal.dump(Foo.new([nil])).unpack("x2 a a c a3 aca*")
# => ["C", ":", 8, "Foo", "[", 6, "0"]
# ^^^ (or '"', '/', '{')
//}
==== String, Regexp, Array, Hash のサブクラス (インスタンス変数あり)
'I' で始まるデータ... -
pack テンプレート文字列 (7.0)
-
pack テンプレート文字列
...ン
//}
: ネットワークバイトオーダの signed long
//emlist[][ruby]{
s = "\xFF\xFF\xFF\xFE"
n = s.unpack("N")[0]
if n[31] == 1
n = -((n ^ 0xffff_ffff) + 1)
end
n # => -2
//}
: ネットワークバイトオーダの signed long(その2)
//emlist[][ruby]{
s = "\xFF\xFF\xFF\xFE"
n = s.u... -
ruby 1
. 8 . 4 feature (7.0) -
ruby 1.8.4 feature ruby 1.8.4 での ruby 1.8.3 からの変更点です。
...8.4 (2005-12-22) [i686-linux]
-:2: syntax error, unexpected tSTRING_CONTENT
alias :"foo" :"bar"
^
-:2: warning: unused literal ignored
# => ruby 1.9.0 (2005-12-10) [i686-linux]
"bar"......すると、それ以降の
バックトラックが効かなくなるバグの修正。((<ruby-list:41328>))
p(/^[a-z]+x[0-9]+$/ =~ "hogex111")
p(/^[\x61-\x7a]+x[0-9]+$/ =~ "hogex111")
# => ruby 1.8.3 (2005-09-21) [i686-linux]
0
nil
#......サンプル兼ライブラリ
#Wed Dec 7 01:02:04 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
#
# * ext/tk/README.macosx-aqua: [new document] tips to avoid the known
# bug on platform specific dialogs of Tcl/Tk Aqua on MacOS X.
MacOS X 上で Aqua 版の Tcl/Tk を用いた...