Module: ReadSource::ReadSource

Defined in:
lib/read_source/read_source.rb

Instance Method Summary collapse

Instance Method Details

#attr?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/read_source/read_source.rb', line 18

def attr?
  (file, line_num = send :source_location) || return
  def_header = IO.readlines(file)[line_num-1]
  def_header[/(attr[\w]*)/].to_sym rescue nil
end

#read_sourceObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/read_source/read_source.rb', line 3

def read_source
  (file, line_num = send :source_location) || return
  readlines = IO.readlines(file)
  source = readlines[line_num-1]
  indent = /\A[[:space:]]*/.match(source).to_s.length
  source = source[indent..-1]
  return source if source =~ /(attr[\w]*)/
  readlines[line_num..-1].each do |line|
    source += line[indent..-1]
    if indent == /\A[[:space:]]*/.match(line).to_s.length
      break source
    end
  end
end