Module: Kernel

Defined in:
lib/mlhch/util.rb

Overview

ml_gems/util.rb

Instance Method Summary collapse

Instance Method Details

#fm(c, m = nil, output = false) ⇒ Object



6
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
33
34
35
36
37
# File 'lib/mlhch/util.rb', line 6

def fm c, m = nil, output = false
  if c.is_a? Class
  current_klass = c
  else
    if c.is_a? Symbol
      current_klass = self.class === Class ? self : self.class
    m = c
    end
  end

  s = ["Searching class method '#{m}' of #{current_klass}..."]
  current_klass.ancestors.each do |klass|
    begin
      s << sprintf("%-40s - %-40s", klass, klass.method(m).source_location.join(':').gsub(/.*(app|gems)\//, ''))
    rescue
      nil
    end
  end
  s << "Searching instance method '#{m}' of #{current_klass}..."
  current_klass.ancestors.each do |klass|
    begin
      s << sprintf("%-40s - %-40s", klass, klass.instance_method(m).source_location.join(':').gsub(/.*(app|gems)\//, ''))
    rescue
      nil
    end
  end
  if output
    return '<pre>' + (s.map { |a| a = ERB::Util.html_escape(a) }.join("\n")) + '</pre>'
  else
    puts s.join("\n")
  end
end

#pcallObject



39
40
41
42
43
# File 'lib/mlhch/util.rb', line 39

def pcall
  caller.reverse.each_with_index do |a, i|
    printf "%3s : %s\n", i, a.gsub(/.*(lib|ruby)\//, '')
  end
end