class RbPlusPlus::RbModule

Class representation of a ruby Module to be exposed in the extension. A Module acts much in the same way as Extension in that it can contain classes, functions, enumerations, etc.

Attributes

modules[RW]

Modules can be nested

name[RW]

Modules have a name

node[R]

Access to the underlying RbGCCXML parser

parent[RW]

Parent module if this is nested

Public Class Methods

new(name, parser, &block) click to toggle source

Registers a new module definition for this extension. Use RbPlusPlus::Extension#module or #module instead of creating an instance of this class directly

The block parameter is optional, you can also grab the reference of the Module and work with it as you want:

module "Name" do |m|
  ...
end

or

m = module "Name"
...

Unlike Extension#new, no special processing is done in the block version, it’s just there for convenience.

# File lib/rbplusplus/module.rb, line 38
def initialize(name, parser, &block)
  @name = name
  @parser = parser
  @modules = []
  @wrapped_functions = []
  @wrapped_classes = []
  @wrapped_structs = []

  block.call(self) if block
end

Public Instance Methods

classes(*args) click to toggle source

As with functions, add to node.classes any classes / structs that have been explicitly given to this module.

# File lib/rbplusplus/module.rb, line 89
def classes(*args)
  [node ? node.classes(*args) : [], @wrapped_classes].flatten
end
enumerations(*args) click to toggle source
# File lib/rbplusplus/module.rb, line 98
def enumerations(*args)
  node ? node.enumerations(*args) : []
end
functions(*args) click to toggle source

Make sure to add to the node.functions any functions specifically given to this module

# File lib/rbplusplus/module.rb, line 83
def functions(*args)
  [node ? node.functions(*args) : [], @wrapped_functions].flatten
end
includes(node) click to toggle source

Add an RbGCCXML::Node to this module. This Node can be a Function, Class or Struct and will get wrapped accordingly

# File lib/rbplusplus/module.rb, line 67
def includes(node)
  if node.is_a?(RbGCCXML::Function)
    @wrapped_functions << node
  elsif node.is_a?(RbGCCXML::Class)
    @wrapped_classes << node
  elsif node.is_a?(RbGCCXML::Struct)
    @wrapped_structs << node
  else
    raise "Cannot use #{self.class}#includes for type '#{node.class}'"
  end

  node.moved_to = self
end
module(name, &block) click to toggle source

Register another module to be defined inside of this module. Acts the same as RbPlusPlus::Extension#module.

# File lib/rbplusplus/module.rb, line 59
def module(name, &block)
  m = RbModule.new(name, @parser, &block)
  m.parent = self
  @modules << m
end
namespace(name) click to toggle source

Specify a C++ namespace from which the contained code will be wrapped and exposed to Ruby under this Module.

Also see RbPlusPlus::Extension#namespace

# File lib/rbplusplus/module.rb, line 53
def namespace(name)
  @node = @parser.namespaces.find(:all, :name => name)
end
qualified_name() click to toggle source

Get the fully nested name of this module

# File lib/rbplusplus/module.rb, line 103
def qualified_name
  if parent
    "#{parent.qualified_name}::#{self.name}"
  else
    self.name
  end
end
structs(*args) click to toggle source

See clases and functions

# File lib/rbplusplus/module.rb, line 94
def structs(*args)
  [node ? node.structs(*args) : [], @wrapped_structs].flatten
end