I have read a couple of questions about Ruby dup and clone method Ruby dup and clone. I understand that dup
doesn't copy the singleton
methods and clone does for any object.
I am trying to check w.r.t class methods but found it bit confusing:-
class User
def self.active
'all active users'
end
end
DupUser = User.dup
DupUser.active #=> all active users'
CloneUser = User.clone
CloneUser.active #=> all active users'
As far as I know, class methods are just singleton methods too, then why does User.dup
copied the active
method i.e actually a singleton method of User
.