레일 코드에서루비 클래스의 <= 연산자는 무엇입니까? 조각 다음
def rescue_from(*klasses, &block)
options = klasses.extract_options!
unless options.has_key?(:with)
if block_given?
options[:with] = block
else
raise ArgumentError, "Need a handler. Supply an options hash that has a :with key as the last argument."
end
end
klasses.each do |klass|
key = if klass.is_a?(Class) && klass <= Exception
klass.name
elsif klass.is_a?(String)
klass
else
raise ArgumentError, "#{klass} is neither an Exception nor a String"
end
# put the new handler at the end because the list is read in reverse
self.rescue_handlers += [[key, options[:with]]]
end
end
end
공지 사항 운영자 < =
그 무엇입니까?
"왜곡 된 연산자 오버로딩"이라고 생각하는 이유는 무엇입니까? 상속 관계 (Inheritance Relationship)는 클래스들에 대한 부분적인 순서를 부과하며, 일반적으로 부분적 순서를 부여하는 관계를 표현하기 위해 사용 된 심볼은'<='(오히려'≤'이지만 Ruby에서 유효한 메소드 이름이지만 유효하지 않습니다 연산자 이름). 서브 타입 관계를 나타 내기위한 일반적인 연산자가'<:'이지만 Ruby에서는 유효한 메소드 나 연산자 이름이 아니므로 개인적으로'<='가 충분히 좋다고 느낍니다. 집합 유니온 ('∪'이어야 함)에'+'를 사용하는 일반적인 남용을 능가합니다. –