Class: ANTLR3::Template::ParameterList

Inherits:
Array
  • Object
show all
Defined in:
lib/antlr3/template.rb,
lib/antlr3/template/parameter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Array

#pad, #pad!

Instance Attribute Details

#blockObject

Returns the value of attribute block.



309
310
311
# File 'lib/antlr3/template.rb', line 309

def block
  @block
end

#splatObject

Returns the value of attribute splat.



309
310
311
# File 'lib/antlr3/template.rb', line 309

def splat
  @splat
end

Class Method Details

.defaultObject



311
312
313
314
315
# File 'lib/antlr3/template.rb', line 311

def self.default
  new.add( :values ) do | p |
    p.default = '{}'
  end
end

Instance Method Details

#add(name, default = nil) ⇒ Object



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/antlr3/template.rb', line 324

def add( name, options = nil )
  param =
    case name
    when Parameter then name
    else Parameter.new( name.to_s )
    end
  if options
    default = options[ :default ] and param.default = default
    param.splat = options.fetch( :splat, false )
    param.block = options.fetch( :block, false )
  end
  block_given? and yield( param )
  push( param )
  return( self )
end

#namesObject



317
318
319
320
321
322
# File 'lib/antlr3/template.rb', line 317

def names
  names = map { | param | param.name.to_s }
  @splat and names << @splat.to_s
  @block and names << @block.to_s
  return( names )
end

#to_sObject



340
341
342
343
344
345
# File 'lib/antlr3/template.rb', line 340

def to_s
  signature = join( ', ' )
  @splat and signature << ", *" << @splat.to_s
  @block and signature << ", &" << @block.to_s
  return( signature )
end