Class: Xumlidot::Types::Argument
- Inherits:
-
Object
- Object
- Xumlidot::Types::Argument
- 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
-
#assign ⇒ Object
Returns the value of attribute assign.
-
#default ⇒ Object
Returns the value of attribute default.
-
#name ⇒ Object
:types # TODO: determine the type of the argument.
Instance Method Summary collapse
-
#initialize ⇒ Argument
constructor
A new instance of Argument.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Argument
Returns a new instance of Argument.
33 34 35 |
# File 'lib/xumlidot/types/argument.rb', line 33 def initialize # @types = [] end |
Instance Attribute Details
#assign ⇒ Object
Returns the value of attribute assign.
27 28 29 |
# File 'lib/xumlidot/types/argument.rb', line 27 def assign @assign end |
#default ⇒ Object
Returns the value of attribute default.
27 28 29 |
# File 'lib/xumlidot/types/argument.rb', line 27 def default @default end |
#name ⇒ Object
: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_s ⇒ Object
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 |