Class: Snackhack2::RubyComments

Inherits:
Object
  • Object
show all
Defined in:
lib/snackhack2/ruby_comments.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ RubyComments

Returns a new instance of RubyComments.



4
5
6
# File 'lib/snackhack2/ruby_comments.rb', line 4

def initialize
	@file = file
end

Instance Attribute Details

#file ⇒ Object

Returns the value of attribute file.



3
4
5
# File 'lib/snackhack2/ruby_comments.rb', line 3

def file
  @file
end

Instance Method Details

#comment_block ⇒ Object



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
# File 'lib/snackhack2/ruby_comments.rb', line 7

def comment_block
	if File.exist?(@file)
	  comments = []
	  in_comment_block = false
	  File.readlines(@file).each do |file|
	    file.each_line do |line|
	      if line.strip.eql? '=begin'
	        in_comment_block = true
	        next
	      elsif line.strip.eql? '=end'
	        in_comment_block = false
	        next
	      end

	      if in_comment_block
	        comments << line
	      end
	    end
	  end
	  comments.each do |c|
	  	puts c
	  end
	else
		puts "#{@file} does not exist."
	end
end

#comments ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/snackhack2/ruby_comments.rb', line 33

def comments
	if File.exist?(@file)
		File.readlines(@file).each do |l|
			line = l.to_s
			if line.to_s.start_with?("#")
				puts l
			end
		end
	else 
		puts "#{@file} does not exist."
	end
end