Sha256: bce6967c8a1cccc93191ce6f365a061fdff6f9c71d6e3f99ff6902fadd542dcd

Contents?: true

Size: 713 Bytes

Versions: 1

Compression:

Stored size: 713 Bytes

Contents

module ReadSource
  module ReadSource
    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

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
read_source-0.2.1 lib/read_source/read_source.rb