Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ineiti/helperclasses
Simple helper-classes for Ruby
https://github.com/ineiti/helperclasses
Last synced: 2 days ago
JSON representation
Simple helper-classes for Ruby
- Host: GitHub
- URL: https://github.com/ineiti/helperclasses
- Owner: ineiti
- License: other
- Created: 2014-05-28T16:57:21.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-07-21T05:23:50.000Z (over 6 years ago)
- Last Synced: 2024-03-15T01:54:25.285Z (9 months ago)
- Language: Ruby
- Size: 37.1 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this 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::DPutsDEBUG_LVL = 5
dputs(5){ "String with some #{huge_db.inspect}" }
```This will evaluate and print the ```huge_db``` variable, while
```
include HelperClasses::DPutsDEBUG_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 = 0ddputs(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::ArraySymp [ "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::HashAccessorp { :a => 2, "a" => 3 }._a
```Will print "2". So symbols have precedence over string-keys.
==== Setting a value
```
using HelperClasses::HashAccessora = { :a => 2, "a" => 3 }
a._a = 4
a._b = 5p a
```Will print ```{ :a => 4, "a" => 3, :b => "5" }```