Build Status Code Climate Gem Version

Acting lets your objects play a role. But just for a specific duration. One of the main-concepts for a clean DCI implementation.


Add this line to your application's Gemfile:

gem 'acting'

And then execute:

$ bundle

Or install it yourself as:

$ gem install acting


It is as simple as this:

class User
  include Acting::Cast

  attr_accessor :name

user1 =
user2 =

module Positivist
  def speak; 'YES'; end

module Negativist
  def speak; 'NO'; end
end => Positivist, user2 => Negativist).play do
  user1.speak # => 'YES'
  user2.speak # => 'NO'

user1.speak # => NoMethodError

Nested Usage

Different actings can also be nested, the defined role-methods will be safely overridden and restored:

# assume the already defined constants
user = => Positivist).play do
  user.speak # => 'YES' => Negativist).play do
    user.speak # => 'NO'

  user.speak # => 'YES'

user.speak # => NoMethodError

Usage without a block

The acting can also be manually started/quit. This can come in handy if you need more control over the program flow or want to use the actual roles later:

# assume the already defined constants
user =

acting = => Positivist)

user.speak # => NoMethodError

user.speak # => 'YES'


user.speak # => NoMethodError


For now, we are only running on MRI 1.9.2/1.9.3/2.0.0. jRuby and RBX need to be configured.

Already defined methods won't be overridden due to the implementation with method_missing. It's to discuss whether this is a bug or a feature.


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request