Custom matcher for ActiveHash. It provides `like` operator.
Ruby Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
bin Initial commit. Feb 29, 2016
test Implemented OR matcher Mar 11, 2016
.gitignore Added vendor directory to gitignore. Feb 29, 2016
.travis.yml Initial commit. Feb 29, 2016
Gemfile Initial commit. Feb 29, 2016
active_hash-like.gemspec Removed allowed_push_host for gem publish. Mar 22, 2016

ActiveHash::Like Build Status

Custom matcher for ActiveHash. It provides like operator.


After install ActiveHash::Like, you can use like method.

class Country < ActiveHash::Base; end 'Cana%')

If you want to use like in the where method parameter, you can use ActiveHash::Match::Like matcher.

# Specify match type.

# Or use forward, backward, partial method.
Country.where(name: ActiveHash::Match::Like.forward('Cana'))

Custom matcher

ActiveHash::Match::Like is one of custom matcher. You can create your custom matcher. It should have call method like the following:

class MyCustomMatcher
  attr_accessor :pattern

  def initialize(pattern)
    self.pattern = pattern

  def call(value)
    # Case ignore matcher
    value.upcase == pattern.upcase


So, you can use Proc object as simple custom matcher.

Country.where(name: ->(value){ value == 'some value'})

OR condition

you can use key: or like the following:

Country.where(name: 'Canada', or: {field1: 'foo', field2: 'bar'})
#=> name = 'Canada' and (field1 = 'foo' or field2 = 'bar')

If you want to use or to one column, you must use custom matcher.

Country.where(name: ->(val){val == 'Canada' || val == 'US'})


Add this line to your application's Gemfile:

gem 'active_hash-like'

And then execute:

$ bundle

Or install it yourself as:

$ gem install active_hash-like


After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to


Bug reports and pull requests are welcome on GitHub at[USERNAME]/active_hash-like.


The gem is available as open source under the terms of the MIT License.