LoginSignup
7
7

More than 5 years have passed since last update.

デフォルトオブジェクトがProcであるHashはダンプできない

Posted at

データを集計してファイルに保存!をやろうとして詰まるやつ

h = Hash.new{[]}
Marshal.dump(h) # => TypeError: can't dump hash with default proc

JSONを噛ませて(Procを浄化して)対処している

h0 = JSON.parse( JSON.dump(h) )
Marshal.dump(h0) # => "\x04\b{\x00"

もうちょっと賢い方法はないものか

Marshal フォーマット

7
7
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7