Class: MethodWriter
- Includes:
- WriteParameters
- Defined in:
- lib/util/MethodWriter.rb
Overview
TODO This instance should replace the write method in ActsAsRuntimeMethod
Instance Method Summary collapse
-
#initialize ⇒ MethodWriter
constructor
A new instance of MethodWriter.
- #write(params, statements, tab = 0, method_id = 0, additional_comments = '') ⇒ Object
Methods included from WriteParameters
#describe_params, #write_params
Constructor Details
#initialize ⇒ MethodWriter
Returns a new instance of MethodWriter.
6 7 8 |
# File 'lib/util/MethodWriter.rb', line 6 def initialize end |
Instance Method Details
#write(params, statements, tab = 0, method_id = 0, additional_comments = '') ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/util/MethodWriter.rb', line 10 def write(params,statements,tab=0,method_id=0,additional_comments='') line = "\n" tab.times {|x| line += "\t" } line += "#\n" params.each_with_index do |var,i| tab.times {|x| line += "\t" } line += "#\t@param\t" # Get a description of the requirements (this can multiple lines) line_prefix = '' desc = var.describe(tab) desc.each_line do |l| line += line_prefix+l # Assides the first line pre-fix a "# " to the start (tab-1).times {|x| line += "\t" } line_prefix = "#\t\t\t" end end # Add some some additional comment if supplied unless additional_comments.nil? tab.times {|x| line += "\t" } line += "#" tab.times {|x| line += "\t" } line += additional_comments+"\n" end tab.times {|x| line += "\t" } line += "#\n" tab.times {|x| line += "\t"} line += 'def method_'+method_id.to_s #line += write_params(@parameters) line += write_params(params) line += "\n" # Write out any statements within the method statements.each do |statement| line += statement.write(tab+1)+"\n" end line += "\n" if statements.empty? # Close the method tab.times {|x| line += "\t" } line += "end"+"\n" return line end |