▶️ Command adds the Command Design Pattern to any Class.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



Build Status: master Gem Version MIT license Maintainability

Command adds the Command Design Pattern to any Class.

This was based on Hanami::Interactor, and started off as adding a direct call on the singleton class, before that was added to Hanami's. After working with different interactors and command-style gems, including ways to organize units for execution and without depending on other utility classes, command was born.

Because command has been taken on rubygems (but not updated since 2013), and commando has been taken (but not updated since 2009) and the Dutch opdracht is probably not pronounceable by most people using this, I've decided to register this on the French commande.

However, if you are using this directly from GitHub, you can continue using it as is, without renaming, as long as you change the Gemfile line to require: 'command'.

# Gemfile
gem 'commande', require: 'command'


Add this line to your application's Gemfile:

gem 'commande'

or alternatively if you would like to refer to commande as Command:

gem 'commande', require: 'command'

And then execute:

$ bundle

Or install it yourself as:

$ gem install commande


There are examples in the code and the tests. Here is a crude and basic example:

class FetchSecondInput
  include Commande
  output :fetched
  def call(*args)
    # always define call
    self.fetched = args.second 
  def valid?(*args)
    args.length == 2
  attr_accessor :fetched

result = FetchSecondInput.call(42, 'gem')
result.successful? # => true
result.fetched # => 'gem'

result = FetchSecondInput.call(42, 'gem', 'three is a crowd')
result.successful? # => false
result.fetched # => nil


There are some Minitest assertions included in this library.

require 'commande/minitest'
Assert Refute
assert_successful(command_result) refute_successful passes if the command is successful?
assert_valid(command, *args_for_valid) refute_valid passes if the command is valid
assert_with_error(expected, actual) refute_with_error passes if the command has a certain error message


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 rubygems.org.


Bug reports and pull requests are welcome on GitHub at SleeplessByte/commmand. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.


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

Code of Conduct

Everyone interacting in the Shrine::ConfigurableStorage project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.