Module: Citrus::Grammar

Defined in:
lib/citrus.rb

Overview

Inclusion of this module into another extends the receiver with the grammar helper methods in GrammarMethods. Although this module does not actually provide any methods, constants, or variables to modules that include it, the mere act of inclusion provides a useful lookup mechanism to determine if a module is in fact a grammar.

Class Method Summary collapse

Class Method Details

.included(mod) ⇒ Object

Extends all modules that include Grammar with GrammarMethods and exposes Module#include.



368
369
370
371
372
# File 'lib/citrus.rb', line 368

def self.included(mod)
  mod.extend(GrammarMethods)
  # Expose #include so it can be called publicly.
  class << mod; public :include end
end

.new(&block) ⇒ Object

Creates a new anonymous module that includes Grammar. If a block is provided, it is +module_eval+'d in the context of the new module. Grammars created with this method may be assigned a name by being assigned to some constant, e.g.:

MyGrammar = Citrus::Grammar.new {}


360
361
362
363
364
# File 'lib/citrus.rb', line 360

def self.new(&block)
  mod = Module.new { include Grammar }
  mod.module_eval(&block) if block
  mod
end