#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
發佈了108 篇原創文章 · 獲贊 0 · 訪問量 2940
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章