1
간화선 코드, 수 75 : 난 그냥 발견했기 때문에Ruby Koan nº 75에서 배울 점은 무엇입니까?
in_ruby_version("mri") do
RubyConstant = "What is the sound of one hand clapping?"
def test_constants_become_symbols
all_symbols = Symbol.all_symbols
assert_equal __, all_symbols.include?(__)
end
end
내가 그것으로 조금 혼란 스러워요 그 "all_symbols.include은 (__)?"일치 "사실"에 대해 테스트 어떤 기호. 예를 들어, 다음의 모든 작동합니다 :
는 모두에서 "constants_become_symbols"로 배울 무엇입니까assert_equal true, all_symbols.include?(:RubyConstant)
assert_equal true, all_symbols.include?(:"What is the sound of one hand clapping?")
assert_equal true, all_symbols.include?(:AnythingElseYouCouldWriteHere)
?
한편, [한 손 박수 소리] (https://www.youtube.com/watch?v=L1tsCOkCoC8) – songe
와우, 고마워! 이 상수는 범위가 제한되어 있습니다. 맞습니까? 아니면 그 종류의 글로벌 물건? –
'RubyConstant'는'AboutSymbols' 클래스에서 정의되었으므로 해당 범위에 바인딩되므로':: AboutSymbols :: RubyConstant'를 사용하여 전역 수준에서 범위 연산자를 통해 액세스해야합니다. 루비 상수에 대한 자세한 내용은 [여기] (http://rubylearning.com/satishtalim/ruby_constants.html)을 참조하십시오. 또한 AboutConstants의 koans를 살펴보십시오. – songe