Class: Reline::KeyActor::Base
- Inherits:
-
Object
- Object
- Reline::KeyActor::Base
- Defined in:
- lib/reline/key_actor/base.rb
Instance Method Summary collapse
- #add(key, func) ⇒ Object
- #clear ⇒ Object
- #get(key) ⇒ Object
- #get_method(key) ⇒ Object
-
#initialize(mapping = []) ⇒ Base
constructor
A new instance of Base.
- #matching?(key) ⇒ Boolean
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 |
#clear ⇒ Object
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
19 20 21 |
# File 'lib/reline/key_actor/base.rb', line 19 def matching?(key) @matching_bytes[key] end |