Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/phoet/idgas
I dont give a shit - Is a helper for handling nil in deep data structures.
https://github.com/phoet/idgas
Last synced: 26 days ago
JSON representation
I dont give a shit - Is a helper for handling nil in deep data structures.
- Host: GitHub
- URL: https://github.com/phoet/idgas
- Owner: phoet
- Created: 2009-09-08T07:04:15.000Z (about 15 years ago)
- Default Branch: master
- Last Pushed: 2009-10-18T10:00:32.000Z (about 15 years ago)
- Last Synced: 2024-05-01T22:35:53.952Z (6 months ago)
- Language: Ruby
- Homepage: http://blog.nofail.de/
- Size: 70.3 KB
- Stars: 8
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
Awesome Lists containing this project
README
= I dont give a shit (idgas)
Inspired by groovys questionmark-syntax. 'I dont give a shit' tries to implement this behavior in ruby.
You can put a ? behind every method-call to ignore, weather it returns nil.
So chaining of calls within deep data-structures is painless:
some_data_that_might_contain_nil.order?.shoppingcart?.item?.second?.price?
This call would return the price of the second item in the shopping-cart or +nil+ if some of the objects in the data-structure is +nil+ itself.
== Install
$ gem install phoet-idgas -s http://gems.github.com
== How to use
Just require the gem and put it in a place where it can override the default behavior of your script.
You might put it as an initializer in your rails application or something like that.$ irb -rubygems
require 'i_dont_give_a_shit'
nil.i?.dont?.give?.a?.shit?
=> nil