Private visibility for class method

L

lianliming

I got to learn that "private" label in a class definition doesn't
apply to class methods. But I saw many existed source code defining
class methods after "private" label. For example, in the book "Agile
Web Development with Rails 2nd", I saw following code snippet:


class User < ActiveRecord::Base
...

def password=(pwd)
.....
end

private

def self.encrypted_password(password, salt)
....
end

end



If private has no effect on the visibility of class method
"self.encrypted_password", I am wondering why the author put its
definition there. This isn't the only place I found class methods are
defined under "private" label. So I guess there may be other
intentions I don't know. Is there anyone giving some hints on this?

Thanks in advance!
 
R

Rados³aw Bu³at

PiBJZiBwcml2YXRlIGhhcyBubyBlZmZlY3Qgb24gdGhlIHZpc2liaWxpdHkgb2YgY2xhc3MgbWV0
aG9kCj4gInNlbGYuZW5jcnlwdGVkX3Bhc3N3b3JkIiwgSSBhbSB3b25kZXJpbmcgd2h5IHRoZSBh
dXRob3IgcHV0IGl0cwo+IGRlZmluaXRpb24gdGhlcmUuIFRoaXMgaXNuJ3QgdGhlIG9ubHkgcGxh
Y2UgSSBmb3VuZCBjbGFzcyBtZXRob2RzIGFyZQo+IGRlZmluZWQgdW5kZXIgInByaXZhdGUiIGxh
YmVsLiBTbyBJIGd1ZXNzIHRoZXJlIG1heSBiZSBvdGhlcgo+IGludGVudGlvbnMgSSBkb24ndCBr
bm93LiBJcyB0aGVyZSBhbnlvbmUgZ2l2aW5nIHNvbWUgaGludHMgb24gdGhpcz8KCkkgZ3Vlc3Mg
dGhhdCBhdXRob3IgZGlkbid0IGtub3cgdGhhdCBpdCB3b24ndCBoYXZlIGFueSBhZmZlY3QuCklu
dHVpdGl2ZWx5IGl0IHNob3VsZCB3b3JrIGFzIGF1dGhvciBleHBlY3RlZCBidXQgaXQgZG9lc24n
dCAoYW5kCnRoZXJlIGFyZSBzb21lIHJlYXNvbikuIElmIHlvdSB3YW50IHRvIG1ha2UgcHJpdmF0
ZS9wcm90ZWN0ZWQgY2xhc3MKbWV0aG9kcyBkbyB0aGlzOgoKY2xhc3MgVXNlciA8IEFjdGl2ZVJl
Y29yZDo6QmFzZQogIGNsYXNzIDw8IHNlbGYKICAgIHByaXZhdGUKCiAgICBkZWYgZW5jcnlwdGVk
X3Bhc3N3b3JkKHBhc3N3b3JkLCBzYWx0KQogICAgICAgLi4uLgogICAgZW5kCiAgZW5kCmVuZAoK
LS0gClJhZG9zs2F3IEJ1s2F0CgpodHRwOi8vcmFkYXJlay5qb2dnZXIucGwgLSBt82ogYmxvZwo=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top