[#42503] floatの値がずれる — Sato Hiroshi <hirocy.f01@...>
hirocyと申します.
33 messages
2006/07/04
[#42504] Re: floatの値がずれる
— rubikitch <rubikitch@...>
2006/07/04
From: Sato Hiroshi <hirocy.f01@plala.to>
[#42505] Re: floatの値がずれる
— Sato Hiroshi <hirocy.f01@...>
2006/07/04
hirocyです.るびきちさん,ありがとうございます.
[#42506] Re: floatの値がずれる
— Sato Hiroshi <hirocy.f01@...>
2006/07/04
続けてですみません.hirocyです.
[#42509] Re: float の値がずれる
— Shin-ichiro HARA <sinara@...>
2006/07/04
原です。
[#42536] Array#default — take_tk <ggb03124@...>
たけ(tk)です
16 messages
2006/07/06
[#42544] Re: Array#default
— Yukihiro Matsumoto <matz@...>
2006/07/06
まつもと ゆきひろです
[#42569] JVN、スクリプト言語「Ruby」の2件の脆弱性情報を公表 — Takahiro Kambe <taca@...>
こんばんは。
19 messages
2006/07/11
[#42570] Re: JVN、スクリプト言語「Ruby」の2件の脆弱性情報を公表
— Yukihiro Matsumoto <matz@...>
2006/07/11
まつもと ゆきひろです
[#42572] Re: JVN、スクリプト言語「Ruby」の2件の脆弱性情報を公表
— Takahiro Kambe <taca@...>
2006/07/11
In message <1152619872.835566.21152.nullmailer@x31.priv.netlab.jp>
[#42575] Re: JVN、スクリプト言語「Ruby」の2件の脆弱性情報を公表
— Yukihiro Matsumoto <matz@...>
2006/07/11
まつもと ゆきひろです
[#42578] Re: JVN、スクリプト言語「Ruby」の2件の脆弱性情報を公表
— Kazuhiko <kazuhiko@...>
2006/07/12
かずひこです。
[#42579] Re: JVN、スクリプト言語「Ruby」の2件の脆弱性情報を公表
— Tanaka Akira <akr@...>
2006/07/12
In article <87irm334qa.wl%kazuhiko@fdiary.net>,
[#42592] Re: JVN、スクリプト言語「Ruby」の2件の脆弱性情報を公表
— Takahiro Kambe <taca@...>
2006/07/19
こんばんは。
[#42599] includeされたmoduleからの定数参照 — 二宗 崇 <nisyu@...>
にしゅうです。
5 messages
2006/07/26
[#42608] Debug Assertion Failed! on stable-snapshot — Shusaku <tsyk@...>
Shusakuです。
5 messages
2006/07/28
[ruby-list:42536] Array#default
From:
take_tk <ggb03124@...>
Date:
2006-07-06 03:29:50 UTC
List:
ruby-list #42536
たけ(tk)です
(1)Hash#default があるのに Array#default は無いようです。何故なんでしょ
うか?
(2)Hash#default でも、hash.default=proc{|hash.key|..} をセットしたと
きに proc.call するタイプの値を許すのはいかがでしょうか? というのは
hash = {}
hash.default = []
p hash[2] #=> [] #=> []
p hash[2][3] #=> nil #=> nil
p hash[2][3]=6 #=> 6 #=> 6
となれば「p hash」は{2=>[nil, nil, nil, 6]}を返すことを期待すると思うの
ですが、現在の仕様では {} が返ります、つまり、「hash[2][3]=6」は見た目と
は異なり、hashには何も作用していません。
p hash #=> {} #=> {2=>[nil, nil, nil, 6]}
proc.call するようにして、参照と同時に作成するように指定できれば、
「hash[2][3]=6」は期待通りの動作を行うようになります。
hash.default = proc{|hash,key| hash[key] = []}
(1)
----
module Array_default
attr :default,true
def [](n)
#
# ブロックを評価するタイプ
# self[]=false、@default = false のときに不具合あり。
#
super(n) || (default && ( defined?(default.call) ? default.call(self,n) : default ))
end
end
array = []
array.extend(Array_default)
array.default = []
array.default = nil
array.default = proc{|arr,n|arr[n] = []} # 自動作成。
p array[2]
p array
p array[2][3]
p array
p array[2][3]=6
p array
p array[2][1]=2
p array
p array[4][2]=8
p array
p array[4][2][1]=8
p array
----
(2)
----
module Hash_default
def [](key)
has_key?(key) ? super(key) : ( defined?(default.call) ? default.call(self,key) : default )
end
end
hash = {}
hash.extend(Hash_default)
hash.default = proc{|hash,key| hash[key] = []}
#hash.default = []
# [] # proc
p hash[2] #=> [] #=> []
p hash #=> {} #=> {2=>[]}
p hash[2][3] #=> nil #=> nil
p hash #=> {} #=> {2=>[]}
p hash[2][3]=6 #=> 6 #=> 6
p hash #=> {} #=> {2=>[nil, nil, nil, 6]}
p hash[2][1]=2 #=> 2 #=> 2
p hash #=> {} #=> {2=>[nil, 2, nil, 6]}
p hash[4][2]=8 #=> 8 #=> 8
p hash #=> {} #=> {2=>[nil, 2, nil, 6], 4=>[nil, nil, 8]}
p hash[4][2][1]=8 #=> undefined method `[]=' for 8:Fixnum (NoMethodError)
p hash
----
(3)hash.default = [] では『オブジェクトの共有』の問題が生じてしまうよ
うです。
---
hash = {}
hash.default = []
p hash[2][3]=6 #=> 6
p hash[4][3]=12 #=> 12
p hash[2][3] #=> 12
----
Take_tk = KUMAGAI Hidetake
たけ(tk)=熊谷秀武