Sha256: 8df99d04f955e7274f3dfc98ca360d7d27453dc11a38b361c69158fc2b239b6c
Contents?: true
Size: 1.08 KB
Versions: 3
Compression:
Stored size: 1.08 KB
Contents
module ReadSource module ReadSource def read_source (file, line_num = send :source_location) || return is_inline_method = ->str{ defs = str.scan(/def(?:\b|ine_method.*do)/).count ends = str.scan(/end/).count def_method_regex = /define_method[ (]+(?::|\w)+[ ),]+(?:{.*}|(?:instance_)?method\((?::|\w)+\)|&\w+)\)?/ defs == ends || str =~ def_method_regex } 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.=~(/\A[[:space:]]*attr[\w]*/) || is_inline_method.(source) 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] return unless def_header =~ /\A[[:space:]]*attr[\w]*/ def_header[/attr[\w]*/].to_sym rescue nil end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
read_source-0.2.4 | lib/read_source/read_source.rb |
read_source-0.2.3 | lib/read_source/read_source.rb |
read_source-0.2.2 | lib/read_source/read_source.rb |