module Qpid::Proton::Util::Constants
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
@private
Public Class Methods
included(base)
click to toggle source
# File lib/util/constants.rb, line 60 def self.included(base) base.extend ClassMethods end