Lambdas Recursivos
why I love Ruby
bookmark_files = lambda do |file| if file.is_bookmarked? my_bookmarks << file elsif file.got_children? file.children.each &bookmark_files end end
February 17, 2011 | En Ruby | No hay comentarios
why I love Ruby
bookmark_files = lambda do |file| if file.is_bookmarked? my_bookmarks << file elsif file.got_children? file.children.each &bookmark_files end end
El formato por defecto del logger de Rails si bien da mucha informacion es algo feo. Para mejorarlo pueden pegar esta modificacion en el archivo environment.rb. El siguiente format_message muestra los logs con colores segun el level y un timestamp
class Logger
NUMBER_TO_COLOR_MAP = {'DEBUG'=>'0;37', 'INFO'=>'32', 'WARN'=>'33', 'ERROR'=>'31', 'FATAL'=>'31', 'UNKNOWN'=>'37'}
def format_message(level, time, progname, msg)
color = NUMBER_TO_COLOR_MAP[level]
"#{time.to_s(:db)} \e[#{color}m#{level.center(7)}\e[0m -- #{msg}\n"
end
endEntradas y comentarios feeds. 13 queries. 0.279 seconds.