gem i omg-attrsgem 'omg-attrs'# Build gem
gem build omg-attrs.gemspec
# Install gem
gem i -l /path/to/this/folder/omg-attrs-<version>.gemOr in a Gemfile
gem 'omg-attrs', path: '/path/to/this/folder'require 'omg-attrs'
dad_hash = {
age: 36,
hair_color: 'brown',
children: [
{ age: 4, hair_color: 'blonde' },
{ age: 8, hair_color: 'brown' }
],
wife: { age: 37, hair_color: 'brown' }
}
dad_hash.attrs(:age) # => { age: 36 }
dad_hash.attrs(wife: :age, children: [:count, :age])
=> {
wife: {
age: 36
},
children: {
count: 2,
items: [
{ age: 8 },
{ age: 4 },
],
},
}
dad_hash.attrs_match?(age: 36, hair_color: 'brown') # => true
dad_hash.children.find_by(age: 4) # => { age: 4, hair_color: 'brown' }
dad_hash.children.where(hair_color: 'brown') # => [{ age: 4, hair_color: 'brown' }]bin/installbin/consolerspec
# or
bundle exec rspec
# or
guard