module Tins::DSLAccessor

The DSLAccessor module contains some methods, that can be used to make simple accessors for a DSL.

class CoffeeMaker
  extend Tins::Constant

  constant :on
  constant :off

  extend Tins::DSLAccessor

  dsl_accessor(:state) { off } # Note: the off constant from above is used

  dsl_accessor :allowed_states, :on, :off

  def process
    allowed_states.include?(state) or fail "Explode!!!"
    if state == on
      puts "Make coffee."
    else
      puts "Idle..."
    end
  end
end

cm = CoffeeMaker.new
cm.instance_eval do
  state      # => :off
  state on
  state      # => :on
  process    # => outputs "Make coffee."
end

Note that Tins::SymbolMaker is an alternative for Tins::Constant in this example. On the other hand SymbolMaker can make debugging more difficult.