Class: Ruby

Inherits:
Object show all
Defined in:
lib/xiki/ruby.rb

Class Method Summary collapse

Class Method Details

.classes(clazz = nil, method = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/xiki/ruby.rb', line 22

def self.classes clazz=nil, method=nil

  # If no params, show list of classes

  if clazz.nil?
    result = []
    ObjectSpace.each_object(Class) do |c|
      name = c.to_s
      next if name =~ /^#/
      result << "- #{name}/\n"
    end
    return result.sort.join
  end

  # If just class, show methods

  if method.nil?
    result = ""
    result << Kernel.const_get(clazz).instance_methods(false).sort.
      collect {|i| "- #{i}/" }.join("\n")
    result << Kernel.const_get(clazz).methods(false).sort.
      collect {|i| "- ::#{i}/" }.join("\n")
    return result
  end

  # If method passed, lookup method's doc

  method = "##{method}" unless method =~ /^::/
  command = "qri #{clazz}#{method}"
  Console[command].gsub(/\C-[.+?m/, '').gsub(/^/, '| ').gsub(/^\| +$/, '|')
end


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/xiki/ruby.rb', line 2

def self.menu
  "
  - .classes/
  - .re_index_fast_ri/
  - .docs/
    > Ruby docs
    @$ qri -h

    > Eval code
    | Evaluate the ruby code on adjascent lines, until a '> ...' heading.
    @eval
    puts('hi')
  - @eval/
  - @technologies/ruby/
  - language docs/
    > Listing and categories of gems
    @ https://www.ruby-toolbox.com/
  "
end

.re_index_fast_riObject



54
55
56
# File 'lib/xiki/ruby.rb', line 54

def self.re_index_fast_ri
  Console.run "fastri-server -b"
end