Câu hỏi phỏng vấn Ruby
Câu hỏi

What is the difference betw...

Câu trả lời

The difference between Ruby's Object#dup and Object#clone methods primarily lies in how they handle the object's frozen state, singleton methods, and taint status.

  1. Frozen State: Object#clone copies the frozen state of the original object. If the original object is frozen, the cloned object will also be frozen. On the other hand, Object#dup does not preserve the frozen state; the duplicated object will be unfrozen even if the original object was frozen[2][3][5][6].

  2. Singleton Methods: Singleton methods (methods defined on an individual object rather than on the class of the object) are copied by Object#clone but not by Object#dup. This means that if you define singleton methods on an object and then clone it, the cloned object will also have these singleton methods. However, if you duplicate the object using Object#dup, the new object will not have the singleton methods[2][3][5][6].

  3. Taint Status: Similar to the frozen state, Object#clone also copies the taint status of the original o...

senior

senior

Gợi ý câu hỏi phỏng vấn

middle

Describe a closure in Ruby

middle

Explain this ruby idiom: a ||= b

senior

Why doesn't Ruby support method overloading?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào