Ruby Koan: Constants become symbols

后端 未结 2 1688
醉酒成梦
醉酒成梦 2020-12-15 10:20

In the about_symbols.rb Ruby Koan (https://github.com/edgecase/ruby_koans), I have the following code:

    RubyConstant = \"What is the sound of one hand cla         


        
2条回答
  •  醉酒成梦
    2020-12-15 10:30

    I'm not a Ruby guru but it looks like interpreter created this symbols during def expression evaluation. That's why these symbols are already there when you call Symbol.all_symbols. Third assert fails with second one being commented out because "string".to_sym creates symbol during methods execution i.e. after you got available symbols with all_symbols = Symbol.all_symbols.

提交回复
热议问题