Module: Qpid::Proton::Util::Constants

Included in:
Disposition
Defined in:
lib/util/constants.rb

Overview

Provides a means for defining constant values within the namespace of a class.

If the class has defined the class method, :post_add_constant, then that method will be invoked after each new item is added. It must be defined before any constants are defined.

Example

class GrammarComponent

  include Qpid::Proton::Constants

  def self.post_add_constant(key, value)
    @terminal << value if value.terminal?
    @nonterminal << value if !value.terminal? && !value.rule
    @rule << value if value.rule
  end

  self.add_constant :LEFT_PARENTHESIS, new GrammarComponent("(", :terminal)
  self.add_constant :RIGHT_PARENTHESIS, new GrammarComponent(")", :terminal)
  self.add_constant :ELEMENT, new GrammarComponent("E", :rule)

  def initialize(component, type)
    @component = component
    @type = type
  end

  def terminal?; @type == :terminal; end

  def rule?; @type == :rule; end

end

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



60
61
62
# File 'lib/util/constants.rb', line 60

def self.included(base)
  base.extend ClassMethods
end