Module: MPatch::Include::Method

Defined in:
lib/mpatch/method.rb

Instance Method Summary collapse

Instance Method Details

#get_commentsObject Also known as: get_description



7
8
9
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
# File 'lib/mpatch/method.rb', line 7

def get_comments

  var= self.source_location.map{|obj| obj.class <= String ? File.absolute_path(obj) : obj }

  file_obj= File.open(var[0],"r")
  file_data= [] #> [*File.open(var[0],"r")]
  var[1].times{ file_data.push file_obj.gets }
  file_data.reverse!

  desc_array= []

  first= true
  file_data.each { |new_string_line|

    if first == true
      first= false
      next
    end

    if new_string_line =~ /^[\s\t]*(#[\s\S]*)?$/

      unless new_string_line.scan(/^[\s\t]*(#\s*)([\s\S]*)?$/).empty?
        new_string_line.replace new_string_line.scan(/^[\s\t]*(#\s*)([\s\S]*)?$/)[0][1]
      end

      if new_string_line.chomp =~ /^\s*$/
        next
      end

      desc_array.push new_string_line.chomp

    else
      break
    end

  }

  #remove nils
  desc_array.compact!

  # return
  return desc_array.join("\n")

end