GitXplorerGitXplorer
h

Emptor

public
3 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
5a160db69852902ea9b9f647c3ca24dd4c939797

Fix formatting for markdown

hhoverbird committed 15 years ago
Unverified
49e6861a4e8a774ea984becf58e67e2914cb7800

Better example

hhoverbird committed 15 years ago
Unverified
92f15651805e77223d8280a5b46bdd9cadb055d5

Better examples

hhoverbird committed 15 years ago
Unverified
7b59adc30040ac928646e8911189a17f2c6ad92c

Better examples

hhoverbird committed 15 years ago
Unverified
e37c613df9b6a99538097f89946d39a9e69bb0b8

Escape underscores in code blocks for Markdown formatting

hhoverbird committed 15 years ago
Unverified
a8fd683b68799052ef066d8be6b2428c0a1d9611

Appending mkdn to the readme

hhoverbird committed 15 years ago

README

The README file for this repository.

Emptor

A convenient conditional that excludes empty objects (Enumerables, in general).

EMPTOR CAVEAT

Emptor is a hack. It's merely a shorter expression for those who want to consider empty collections to be falsy. Calling

$ this._or_ that

Returns the first object that's either a non-empty collection (collections are assumed if the operand responds_to :empty?) or a non-collection that's truthy (in the Colbertian sense). So:

$ []._or_ [1,2,3]
# => [1,2,3]

$ "yep"._or_ [1,2,3]
# => "yep"

$ []._or_ []
# => nil

One example of usage would be while performing an ActiveRecord find with scoping, where you'd like to return an unscoped set if the first set turns out empty.

This:

$ User.all.with_photos.present? ? User.all.with_photos : User.all

Becomes:

$ Person.all.with_photos._or_ Person.all

That's all, folks.