小编cod*_*ode的帖子

Ruby Koans:为什么要将符号列表转换为字符串

我在Ruby Koans的about_symbols.rb中引用了这个测试 https://github.com/edgecase/ruby_koans/blob/master/src/about_symbols.rb#L26

def test_method_names_become_symbols
  symbols_as_strings = Symbol.all_symbols.map { |x| x.to_s }
  assert_equal true, symbols_as_strings.include?("test_method_names_become_symbols")
end


  # THINK ABOUT IT:
  #
  # Why do we convert the list of symbols to strings and then compare
  # against the string value rather than against symbols?
Run Code Online (Sandbox Code Playgroud)

为什么我们必须先将该列表转换为字符串?

ruby

80
推荐指数
3
解决办法
9717
查看次数

标签 统计

ruby ×1