클래스 캡슐화 된 메서드에서 아래 코드의 check_url
개인 메서드에 액세스 할 수없는 이유는 무엇입니까?내부 클래스에서 개인 메서드에 액세스 할 수 없습니까?
class Link < MyModel
# whitelist fields for security
attr_accessible :is_valid,
:url
# validations
validates :is_valid, :inclusion => { :in => [true, false] }
validates :url, :presence => true
# ===============================================================
# = class methods (accessible from outside without an instance) =
# ===============================================================
class << self
def is_url_valid(url)
unless link = Link.find_by_url(url)
link = Link.create!(:url => url, :is_valid => check_url(url))
end
link.is_valid
end
end
# =====================
# = Private functions =
# =====================
private
# Checks if url is broken
def check_url(url)
# do stuff
end
end
PS. 또한 self.check_url
을 사용해 보았는데 작동하지 않았습니다.
코드가 이미 있습니다. 작동하지 않습니다. 나는'self.check_url'과'check_url'을 모두 시도했습니다. – user1049097
제 답변이 업데이트되었습니다. – miaout17
감사. 그게 효과가있어 - 내가 자체 참조 클래스 내에 포함되어 있지 않으면 기본 클래스에서 개인 함수에 액세스 할 수 없다는 것을 몰랐다. – user1049097