Koan code, number 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
I’m a bit confused with it because I’ve just found that any symbol tested against the “all_symbols.include?(__)” will match “true”. For example, all of the following should work:
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)
What is it to learn with “constants_become_symbols” at all?
In ruby, variables that start with capital letters become constants. The goal of the koan is to teach you that constants become symbols in ruby and get added to the ruby’s symbols table.
Also notice how it says
"RubyConstant".to_syminstead of:RubyConstant. It’s to avoid confusion since the ruby interpreter will automatically create a symbol when it parses a ruby function, as explained here.