Class: Reline::KeyActor::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/reline/key_actor/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(mapping = []) ⇒ Base

Returns a new instance of Base.



2
3
4
5
6
# File 'lib/reline/key_actor/base.rb', line 2

def initialize(mapping = [])
  @mapping = mapping
  @matching_bytes = {}
  @key_bindings = {}
end

Instance Method Details

#add(key, func) ⇒ Object



12
13
14
15
16
17
# File 'lib/reline/key_actor/base.rb', line 12

def add(key, func)
  (1...key.size).each do |size|
    @matching_bytes[key.take(size)] = true
  end
  @key_bindings[key] = func
end

#clearObject



27
28
29
30
# File 'lib/reline/key_actor/base.rb', line 27

def clear
  @matching_bytes.clear
  @key_bindings.clear
end

#get(key) ⇒ Object



23
24
25
# File 'lib/reline/key_actor/base.rb', line 23

def get(key)
  @key_bindings[key]
end

#get_method(key) ⇒ Object



8
9
10
# File 'lib/reline/key_actor/base.rb', line 8

def get_method(key)
  @mapping[key]
end

#matching?(key) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/reline/key_actor/base.rb', line 19

def matching?(key)
  @matching_bytes[key]
end