Ruby:console.log?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12550663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ruby: console.log?
提问by BrainLikeADullPencil
I recently put console.log statements in every line of a JavaScript program and found that it's now much easier to understand. Is there a way to do that with server side code, specifically Ruby? I presume there's no way to read it in firebug, but would it be visible in irb? what console.log equivalent statements would I put in the Ruby code?
我最近将 console.log 语句放在 JavaScript 程序的每一行中,发现现在更容易理解了。有没有办法用服务器端代码来做到这一点,特别是 Ruby?我认为没有办法在萤火虫中读取它,但它会在 irb 中可见吗?我将在 Ruby 代码中放入哪些 console.log 等效语句?
回答by mash
putsis the equivalent in ruby.
puts在 ruby 中是等价的。
回答by Daniel Evans
If you are running your server in the console, you can use puts. Otherwise, you will need to write to a file, possibly via a logger (like Rails.logger.info).
如果您在控制台中运行服务器,则可以使用puts. 否则,您将需要写入文件,可能是通过记录器(如Rails.logger.info)。

