Inspecting Marshal methods

后端 未结 1 880
旧巷少年郎
旧巷少年郎 2021-01-25 10:20

Marshal.dump is unable to dump classes that include a singleton(eigenclass). I\'d like to see how the method determines the presence of this singleton but I do not know how to

相关标签:
1条回答
  • 2021-01-25 11:01

    The check is here, but it is in C - and MRI code is infamously opaque.

    I believe a check similar to that, but in Ruby, would be:

    obj.singleton_class.instance_methods(false).empty? &&
    obj.singleton_class.instance_variables.empty?
    

    If that is false (i.e. if anything is defined on the singleton), no dump for you.

    0 讨论(0)
提交回复
热议问题