Class: LanguageParser::LanguageClass
- Inherits:
-
Object
- Object
- LanguageParser::LanguageClass
- Defined in:
- lib/cgialib/lp/Language.rb
Overview
class : LanguageClass
This is a simple data structure that defines what we know about a given class. Ruby already has a class named ‘Class’, so we called this one ‘LanguageClass’ to avoid collisions.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#comments ⇒ Object
The text of any comments.
-
#methods ⇒ Object
readonly
The array of methods.
-
#name ⇒ Object
The name of the class.
-
#parents ⇒ Object
readonly
An array of parent class names.
-
#type ⇒ Object
The type of class (could be interface, or struct).
-
#variables ⇒ Object
readonly
The array of instance variables (or constants).
Instance Method Summary collapse
-
#add_method(method) ⇒ Object
add_method( method ).
-
#add_parent(parent) ⇒ Object
add_parent( parent ).
-
#add_variable(variable) ⇒ Object
add_variable( variable ).
-
#initialize ⇒ LanguageClass
constructor
initialize().
-
#to_s ⇒ Object
to_s().
Constructor Details
#initialize ⇒ LanguageClass
initialize()
Constructor
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/cgialib/lp/Language.rb', line 75 def initialize() @type = "class" @name = "" @comments = "" @parents = [] @methods = [] @variables = [] end |
Instance Attribute Details
#comments ⇒ Object
The text of any comments
90 91 92 |
# File 'lib/cgialib/lp/Language.rb', line 90 def comments @comments end |
#methods ⇒ Object (readonly)
The array of methods
88 89 90 |
# File 'lib/cgialib/lp/Language.rb', line 88 def methods @methods end |
#name ⇒ Object
The name of the class
87 88 89 |
# File 'lib/cgialib/lp/Language.rb', line 87 def name @name end |
#parents ⇒ Object (readonly)
An array of parent class names
91 92 93 |
# File 'lib/cgialib/lp/Language.rb', line 91 def parents @parents end |
#type ⇒ Object
The type of class (could be interface, or struct)
86 87 88 |
# File 'lib/cgialib/lp/Language.rb', line 86 def type @type end |
#variables ⇒ Object (readonly)
The array of instance variables (or constants)
89 90 91 |
# File 'lib/cgialib/lp/Language.rb', line 89 def variables @variables end |
Instance Method Details
#add_method(method) ⇒ Object
add_method( method )
method - The method object
Adds a method
99 100 101 |
# File 'lib/cgialib/lp/Language.rb', line 99 def add_method( method ) @methods.push( method ) end |
#add_parent(parent) ⇒ Object
add_parent( parent )
parent - The parent name as text
Adds a parent class
109 110 111 |
# File 'lib/cgialib/lp/Language.rb', line 109 def add_parent( parent ) @parents.push( parent ) end |
#add_variable(variable) ⇒ Object
add_variable( variable )
variable - The variable object
Adds a variable to the class definition
119 120 121 |
# File 'lib/cgialib/lp/Language.rb', line 119 def add_variable( variable ) @variables.push( variable ) end |
#to_s ⇒ Object
to_s()
Pretty printing string converter
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/cgialib/lp/Language.rb', line 127 def to_s() text = "class : #{@name} - " text += @parents.join( ", " ) text += "\n" text += "Methods:\n" methods.each { |method| text += " #{method}\n" } text += "Variables:\n" variables.each { |var| text += " #{var}\n" } text end |