60件ヒット
[1-60件を表示]
(0.063秒)
キーワード
- Marshal フォーマット (12)
- pack テンプレート文字列 (12)
-
ruby 1
. 6 feature (12) -
ruby 1
. 8 . 4 feature (12) - パターンマッチ (12)
検索結果
-
パターンマッチ (139.0)
-
パターンマッチ * patterns * variable_binding * variable_pinning * matching_non_primitive_objects * guard_clauses * current_feature_status * pattern_syntax * some_undefined_behavior_examples
...ターンは配列の 「全ての」 要素がマッチする必要があるということです。
//emlist[][ruby]{
case [1, 2, 3]
in [Integer, Integer]
"matched"
else
"not matched"
end
#=> "not matched"
//}
一方 Hash パターン は一部のキーだけ指定している場合(指定......場合には、『**nil』 を使います。
//emlist[][ruby]{
case {a: 1, b: 2}
in {a: Integer, **nil} # a: 以外のキーがある場合にはマッチしない
"matched a part"
in {a: Integer, b: Integer, **nil}
"matched a whole"
else
"not matched"
end
#=> "matched a whole"
//}
Array......チする構文をサポートしています。
//emlist[][ruby]{
case [1, 2, 3]
in [Integer, *]
"matched"
else
"not matched"
end
#=> "matched"
//}
//emlist[][ruby]{
case {a: 1, b: 2, c: 3}
in {a: Integer, **}
"matched"
else
"not matched"
end
#=> "matched"
//}
case 文 (単体の in 文......チする構文をサポートしています。
//emlist[][ruby]{
case [1, 2, 3]
in [Integer, *]
"matched"
else
"not matched"
end
#=> "matched"
//}
//emlist[][ruby]{
case {a: 1, b: 2, c: 3}
in {a: Integer, **}
"matched"
else
"not matched"
end
#=> "matched"
//}
case 文 (in 文や => で......チする構文をサポートしています。
//emlist[][ruby]{
case [1, 2, 3]
in [Integer, *]
"matched"
else
"not matched"
end
#=> "matched"
//}
//emlist[][ruby]{
case {a: 1, b: 2, c: 3}
in {a: Integer, **}
"matched"
else
"not matched"
end
#=> "matched"
//}
Array パターン や Hash... -
ruby 1
. 6 feature (55.0) -
ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。
...from -:2
ruby 1.6.7 (2002-07-30) [i586-linux]
: 2002-06-03 sprintf()
"%d" で引数を整数にするときに、((<組み込み関数/Integer>)) と同じ規則を
使用するようになりました。
p sprintf("%d", nil)
=> -:1:in `sprintf': no implicit conversio......:in `remove_instance_variable': instance variable @foo not defined (NameError)
ruby 1.6.7 (2002-04-10) [i586-linux]
: 2002-04-04: Integer#((<Integer/step>))
第二引数が 1 よりも小さい場合に 0 を指定したと見なされエラーになって
いました。
1.ste.......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... -
pack テンプレート文字列 (31.0)
-
pack テンプレート文字列
...] # 仮数部
//}
そして、s, e, f の意味は以下の通りです。
//emlist[][ruby]{
sgn = s == "0" ? +1.0 : -1.0
exp = Integer("0b" + e)
fra = Integer("0b" + f)
if exp == 0
if fra == 0
sgn * 0 # ±0 (positive/negative zero)
else
sgn * fra * 2**(-126-23......,52] # 仮数部
//}
そして、s, e, f の意味は以下の通りです。
//emlist[][ruby]{
sgn = s == "0" ? +1.0 : -1.0
exp = Integer("0b" + e)
fra = Integer("0b" + f)
if exp == 0
if fra == 0
sgn * 0 # ±0 (positive/negative zero)
else
sgn * fra * 2**(-1022-5......ン
//}
: ネットワークバイトオーダの 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 (31.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"......:35 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
#
# * sprintf.c (rb_str_format): integer overflow check added.
#
# * sprintf.c (GETASTER): ditto.
printfのフォーマット指定子にinteger overflowのバグがありました。
perl のそれとは違い、セキュリテ......サンプル兼ライブラリ
#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 を用いた... -
Marshal フォーマット (13.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' で始まるデータ......存はなくなりました。
=== Bignum
'l' で始まるデータ構造になります。
32ビット環境で内部的に Bignum になる Integer は
64ビット環境で Marshal.dump しても、この形式になります。
//emlist{
| 'l' | '+'/'-' | shortの個数(Fixnum形式) | ... |...