Sha256: 07ef16f7112852c6b884ddb007f6b213455432bdbc469d046795888f1cd8fbce

Contents?: true

Size: 601 Bytes

Versions: 1

Compression:

Stored size: 601 Bytes

Contents

module Kan
  module Abilities
    def self.included(base)
      base.extend(ClassMethods)
    end

    module ClassMethods
      def register(*abilities, &block)
        @ability_list ||= {}
        abilities.each { |ability| @ability_list[ability.to_sym] = block }
      end

      def ability_list
        @ability_list || {}
      end
    end

    DEFAULT_ABILITY_BLOCK = proc { true }

    def initialize(options = {})
      @options = options
    end

    def ability(name)
      self.class.ability_list[name.to_sym] || @options[:default_ability_block] || DEFAULT_ABILITY_BLOCK
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kan-0.1.0 lib/kan/abilities.rb