Skip to content

Instantly share code, notes, and snippets.

@hpneo
Created December 20, 2012 06:01
Show Gist options
  • Save hpneo/4343241 to your computer and use it in GitHub Desktop.
Save hpneo/4343241 to your computer and use it in GitHub Desktop.
ActiveRecord-like methods for arrays of objects (usage)
collection = [{
title : 'Product #1',
price : 10.00,
created_at : '2012-12-20'
}, {
title : 'Product #2',
price : 15.00,
created_at : '2012-12-10'
}, {
title : 'Product #3',
price : 1.00,
created_at : '2012-12-21'
}];
product_1 = collection.where({
title : 'Product #1'
}).first();
cheapest_products = collection.where('title LIKE ?', '%Prod%').where('price <= ?', 5.00);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment