Class: Xumlidot::Types::Argument

Inherits:
Object
  • Object
show all
Defined in:
lib/xumlidot/types/argument.rb

Overview

Value object for an argument as specified within a methods definition.

e.g. def foo(a, b)

a and b are the arguments

Depending on the argument; type (TODO), assign and default may be unpopulated e.g.

def foo(a, b)

will be parsed with an empty assign and default, whereas

def bar(a = 1, b = nil)

will both have an assign of ‘=’ and defaults of 1 and :nil respectively.

This is :nil rather than nill since an assignment to a variable of nil is parsed in Args and the default value set to the symbol :nil

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeArgument

Returns a new instance of Argument.



33
34
35
# File 'lib/xumlidot/types/argument.rb', line 33

def initialize
  # @types = []
end

Instance Attribute Details

#assignObject

Returns the value of attribute assign.



27
28
29
# File 'lib/xumlidot/types/argument.rb', line 27

def assign
  @assign
end

#defaultObject

Returns the value of attribute default.



27
28
29
# File 'lib/xumlidot/types/argument.rb', line 27

def default
  @default
end

#nameObject

:types # TODO: determine the type of the argument



31
32
33
# File 'lib/xumlidot/types/argument.rb', line 31

def name
  @name
end

Instance Method Details

#to_sObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/xumlidot/types/argument.rb', line 41

def to_s
  str_default = case default
                when :nil
                  'nil'
                when String
                  default
                when NilClass
                  nil
                when Symbol
                  ":#{default}"
                when Hash
                  '{}' # TODO: Some hashes were crashing the parser, why?
                else
                  default.to_s
                end

  [@name, @assign, str_default || nil].compact.join(' ')
end