gem i omg-attrs
gem 'omg-attrs'
# Build gem
gem build omg-attrs.gemspec
# Install gem
gem i -l /path/to/this/folder/omg-attrs-<version>.gem
require 'omg-attrs'
dad_hash = {
age: 35,
hair_color: 'brown',
children: [
{ age: 7, hair_color: 'blonde' },
{ age: 3, hair_color: 'brown' }
],
wife: { age: 35, hair_color: 'brown' }
}
dad_hash.attrs(:age)
=> { age: 35 }
dad_hash.attrs(wife: :age, children: [:count, :age])
=> {
wife: {
age: 35
},
children: {
count: 2,
items: [
{ age: 7 },
{ age: 3 },
],
},
}
dad_hash.matches?(age: 35) # => true
dad_hash.children.find_by(age: 7) # => { age: 7, hair_color: 'blonde' }
bin/install
bin/console
rspec
# or
bundle exec rspec
# or
guard