Class: Duby::AST::JRubyAst::ArgsNode

Inherits:
Object
  • Object
show all
Defined in:
lib/duby/transform.rb

Instance Method Summary collapse

Instance Method Details

#argsObject



272
273
274
275
276
277
278
279
280
# File 'lib/duby/transform.rb', line 272

def args
  has_typed = optional &&
      optional.child_nodes.all? {|n| n.kind_of? TypedArgumentNode}
  if has_typed
    optional
  else
    pre
  end
end

#transform(transformer, parent) ⇒ Object



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/duby/transform.rb', line 282

def transform(transformer, parent)
  Arguments.new(parent, position) do |args_node|
    arg_list = args.child_nodes.map do |node|
      if !node.respond_to?(:type_node) || node.type_node.respond_to?(:type_reference)
        RequiredArgument.new(args_node, node.position, node.name)
      else
        OptionalArgument.new(args_node, node.position, node.name) {|opt_arg| [transformer.transform(node, opt_arg)]}
      end
      # argument nodes will have type soon
      #RequiredArgument.new(args_node, node.name, node.type)
    end if args

    # TODO optional arguments.
    opt_list = optional.child_nodes.map do |node|
      OptionalArgument.new(args_node, node.position) {|opt_arg| [transformer.transform(node, opt_arg)]}
    end if false && optional

    rest_arg = RestArgument.new(args_node, rest.position, rest.name) if rest

    block_arg = BlockArgument.new(args_node, block.position, block.name) if block

    [arg_list, opt_list, rest_arg, block_arg]
  end
end