Class: Bombshell::Completor

Inherits:
Object
  • Object
show all
Defined in:
lib/bombshell/completor.rb

Overview

A class used by IRB.start_session to handle tab completion.

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Completor) initialize(shell)

Always initialize Completor with the shell it's completing for.



5
6
7
# File 'lib/bombshell/completor.rb', line 5

def initialize(shell)
  @shell = shell
end

Instance Attribute Details

- (Object) shell (readonly)

Returns the value of attribute shell



9
10
11
# File 'lib/bombshell/completor.rb', line 9

def shell
  @shell
end

Class Method Details

+ (Object) filter(m)

Filter out irrelevant methods that shouldn't appear in a completion list.



18
19
20
21
22
# File 'lib/bombshell/completor.rb', line 18

def self.filter(m)
  (m - Bombshell::Environment.instance_methods - Bombshell::Shell::Commands::HIDE).reject do |m|
    m =~ /^_/
  end
end

Instance Method Details

- (Object) complete(fragment)

Provide completion for a given fragment.

Parameters:

  • fragment (String)

    the fragment to complete for



13
14
15
# File 'lib/bombshell/completor.rb', line 13

def complete(fragment)
  self.class.filter(shell.instance_methods).grep Regexp.new(Regexp.quote(fragment))
end