0.0
No commit activity in last 3 years
No release in over 3 years
Added accessors to Hash, to_sym to Array and a nice debugging-interface called DPuts
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

== HelperClasses

Some simple classes to help in everyday tasks

=== DPuts

Ever wanted to have detailed debug-output, but in the end even PRODUCING the string without printing it was too long? Here comes DPuts! It let's you define different debug-levels and the strings are only evaluated if they're about to be printed! Great for that 10MB-dump that you only want for debugging...

Usage:

include HelperClasses::DPuts

DEBUG_LVL = 5
dputs(5){ "String with some #{huge_db.inspect}" }

This will evaluate and print the huge_db variable, while

include HelperClasses::DPuts

DEBUG_LVL = 4
dputs(5){ "String with some #{huge_db.inspect}" }

will NOT evaluate it! The debug-levels are arbitrarily chosen like this:

0 - Errors 1 - Info and warnings, important 2 - Often used debug-messages - limit of production-use 3 - More detailed debugging 4 5 - Dumping lots of raw data

==== Fine-grained debugging

If you have a function with lots of dputs in it, and you'd like to output all debugging messages just from that function, you simply add

dputs_func

at the beginning of your function.

If you want just one specific dputs to be evaluated, just change its name to ddputs:

DEBUG_LVL = 0

ddputs(5){"String with lots of data#{huge_var.inspect}"}

will be evaluated!

=== Arraysym

to_sym and to_sym! - calls .to_sym on all elements. Usage:

using HelperClasses::ArraySym

p [ "a", "b" ].to_sym

Produces "[ :a, :b ]"

=== HashAccessor

This should be standard ruby. Access all elements of an array by prepending a "_".

==== Getting a value

using HelperClasses::HashAccessor

p { :a => 2, "a" => 3 }._a

Will print "2". So symbols have precedence over string-keys.

==== Setting a value

using HelperClasses::HashAccessor

a = { :a => 2, "a" => 3 }
a._a = 4
a._b = 5

p a

Will print { :a => 4, "a" => 3, :b => "5" }