Class: Ray::Key
- Inherits:
-
Object
- Object
- Ray::Key
- Defined in:
- lib/ray/dsl/matcher.rb
Overview
A Key object can be used as a matcher to check if a key has been pressed or released:
on :key_press, Key.new(:+) do
# work
end
Instance Method Summary collapse
- #===(other) ⇒ Object
-
#initialize(name) ⇒ Key
constructor
A new instance of Key.
- #inspect ⇒ Object
- #to_a ⇒ Object
- #to_sym ⇒ Object
Constructor Details
#initialize(name) ⇒ Key
Returns a new instance of Key.
194 195 196 197 |
# File 'lib/ray/dsl/matcher.rb', line 194 def initialize(name) raise NoKeyError, name unless Keys[name] @symbol = name.to_sym end |
Instance Method Details
#===(other) ⇒ Object
207 208 209 |
# File 'lib/ray/dsl/matcher.rb', line 207 def ===(other) to_a.include? other end |
#inspect ⇒ Object
211 212 213 |
# File 'lib/ray/dsl/matcher.rb', line 211 def inspect "key(#{to_sym})" end |
#to_a ⇒ Object
199 200 201 |
# File 'lib/ray/dsl/matcher.rb', line 199 def to_a Keys[@symbol] end |
#to_sym ⇒ Object
203 204 205 |
# File 'lib/ray/dsl/matcher.rb', line 203 def to_sym @symbol end |