class Sith::Macro
Attributes
labels[R]
stararg[R]
template[R]
Public Class Methods
new(labels, stararg=false, template='')
click to toggle source
# File lib/sith/macro.rb, line 31 def initialize(labels, stararg=false, template='') @stararg = stararg @labels = labels @template = template end
Public Instance Methods
expand_to_source(nodes)
click to toggle source
# File lib/sith/macro.rb, line 37 def expand_to_source(nodes) if @stararg substitutions = {@labels[0] => represent(nodes)} else representations = nodes.map { |node| represent node } substitutions = Hash[@labels.zip(representations)] end @template.gsub(/~\{(\w+)\}/) do |label| substitutions[Regexp.last_match(1).to_sym] end end