Module: Quickl::RubyTools

Defined in:
lib/quickl/ruby_tools.rb

Class Method Summary collapse

Class Method Details

.class_unqualified_name(clazz) ⇒ Object

Returns the unqualified name of a class



12
13
14
15
# File 'lib/quickl/ruby_tools.rb', line 12

def class_unqualified_name(clazz)
  name = clazz.name
  (name =~ /::([^:]+)$/) ? $1 : name
end

.extract_file_rdoc(file, from = nil, reverse = false) ⇒ Object

Extracts the rdoc of a given ruby file source.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/quickl/ruby_tools.rb', line 33

def extract_file_rdoc(file, from = nil, reverse = false)
  lines = File.readlines(file)
  if from.nil? and reverse
    lines = lines.reverse
  elsif !reverse
    lines = lines[(from || 0)..-1]
  else
    lines = lines[0...(from || -1)].reverse
  end
  
  doc, started = [], false
  lines.each{|line|
    if /^\s*[#]/ =~ line
      doc << line
      started = true
    elsif started
      break
    end 
  }
  
  doc = reverse ? doc.reverse[0..-1] : doc[0..-1]
  doc = doc.join("\n")
  doc.gsub(/^\s*[#] ?/, "")
end

.optional_args_block_call(block, args) ⇒ Object

Makes a call to a block that accepts optional arguments



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/quickl/ruby_tools.rb', line 19

def optional_args_block_call(block, args)
  if RUBY_VERSION >= "1.9.0"
    if block.arity == 0
      block.call
    else
      block.call(*args)
    end
  else
    block.call(*args)
  end
end

.parent_module(clazz) ⇒ Object

Returns the parent module of a class



5
6
7
8
# File 'lib/quickl/ruby_tools.rb', line 5

def parent_module(clazz)
  name = clazz.name
  (name =~ /^(.*?)::([^:]+)$/) ? Kernel.eval($1) : nil
end