Class: Ray::Key

Inherits:
Object
  • Object
show all
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

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Key

Returns a new instance of Key.

Raises:



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

#inspectObject



211
212
213
# File 'lib/ray/dsl/matcher.rb', line 211

def inspect
  "key(#{to_sym})"
end

#to_aObject



199
200
201
# File 'lib/ray/dsl/matcher.rb', line 199

def to_a
  Keys[@symbol]
end

#to_symObject



203
204
205
# File 'lib/ray/dsl/matcher.rb', line 203

def to_sym
  @symbol
end