Class: Context::Key
Overview
Represents a keypress. Each key is represented by a character and a modifier (e.g., the control key)
One could argue that this doesn’t deserve to be here at all. It is possible that some UI types won’t have a keyboard at all. However given that most will operate the same way indicates that it should have some level of abstraction. I have a feeling that this is YAGNI, though. And as such it might disappear at any point.
Direct Known Subclasses
Defined Under Namespace
Classes: Modifier
Instance Attribute Summary collapse
-
#character ⇒ Object
readonly
Returns the value of attribute character.
-
#modifier ⇒ Object
readonly
Returns the value of attribute modifier.
Class Method Summary collapse
-
.null ⇒ Object
A non key that can be used as an error condition.
Instance Method Summary collapse
-
#eql?(key) ⇒ Boolean
Returns true if the two keys have the same character and modifier.
-
#hash ⇒ Object
Creates a hash for the key.
-
#initialize(modifier, character) ⇒ Key
constructor
A new instance of Key.
-
#null? ⇒ Boolean
Returns true if the key is equal to Key.null.
Constructor Details
#initialize(modifier, character) ⇒ Key
Returns a new instance of Key.
26 27 28 29 |
# File 'lib/Context/Key.rb', line 26 def initialize(modifier, character) @modifier = modifier @character = character end |
Instance Attribute Details
#character ⇒ Object (readonly)
Returns the value of attribute character.
24 25 26 |
# File 'lib/Context/Key.rb', line 24 def character @character end |
#modifier ⇒ Object (readonly)
Returns the value of attribute modifier.
24 25 26 |
# File 'lib/Context/Key.rb', line 24 def modifier @modifier end |
Class Method Details
Instance Method Details
#eql?(key) ⇒ Boolean
Returns true if the two keys have the same character and modifier.
40 41 42 |
# File 'lib/Context/Key.rb', line 40 def eql?(key) (@modifier == key.modifier) && (@character == key.character) end |
#hash ⇒ Object
Creates a hash for the key. This is needed for the KeyMap which is implemented as a hash.
46 47 48 49 50 |
# File 'lib/Context/Key.rb', line 46 def hash hashValue = @modifier.to_s hashValue += @character hashValue.hash end |