Common Ruby Idioms

前端 未结 15 1992
星月不相逢
星月不相逢 2020-12-07 07:13

One thing I love about ruby is that mostly it is a very readable language (which is great for self-documenting code)

However, inspired by this question: Ruby Code ex

15条回答
  •  萌比男神i
    2020-12-07 07:30

    You can deepcopy with Marshaling object easily. - taken from The Ruby Programming Language

    def deepcopy(o)
      Marshal.load(Marshal.dump(o))
    end
    

    Note that files and I/O streams, as well as Method and Binding objects, are too dynamic to be marshaled; there would be no reliable way to restore their state.

提交回复
热议问题