- 791 名前:デフォルトの名無しさん mailto:sage [2009/05/08(金) 23:26:20 ]
- Rubyユーザとは思えない>>772のレスのせいで初心者が混乱しかねないので、
一応言っとく。 ○デフォルト値はあってもMarshalできる(もちろんpstoreも) h = Hash.new(1) h = Marshal.load(Marshal.dump(h)) p h[:foo] #=> 1 ○ダメなのはdefault_proc h = Hash.new {} Marshal.dump(h) #=> can't dump hash with default proc (TypeError) ○default_procはHash#default=で消せる h = Hash.new {} h.default = nil h = Marshal.load(Marshal.dump(h)) p h #=> {} ○配列にデフォルト値などない a = [] a.default = 1 #=> undefined method `default=' for []:Array (NoMethodError)
|

|