`
CaiDeHen
  • 浏览: 94275 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

#86 Logging Variables

阅读更多
Have you ever wanted to easily log all variables? Now you can by using some advanced Ruby concepts as shown in this episode.
# models/product.rb
logger.debug_variables(binding)

# config/initializers/logger_additions.rb
logger = ActiveRecord::Base.logger
def logger.debug_variables(bind)
  vars = eval('local_variables + instance_variables', bind)
  vars.each do |var|
    debug  "#{var} = #{eval(var, bind).inspect}"
  end
end
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics