cdjtkshhg 2022-05-09 14:48
浏览 3
已结题

RUBY里面puts "price is " + game.respond_to?("price").to_s为什么要后面的to_s

如果不加后面的to_s,则会报错

instance_method.rb:33:in +': no implicit conversion of false into String (TypeError) from instance_method.rb:33:in

'

img

  • 写回答

1条回答 默认 最新

  • cdjtkshhg 2022-05-09 15:06
    关注

    有的时候需要对对象的内容进行处理,往往需要先用to_s方法转换成字符串,然后才能处理。

    评论

报告相同问题?

问题事件

  • 系统已结题 5月17日
  • 创建了问题 5月9日