Class: Ray::KeyMod

Inherits:
Object
  • Object
show all
Defined in:
lib/ray/dsl/matcher.rb

Overview

A KeyMod object can be used as a matcher to check if some modifiers are held when a key is pressed.

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ KeyMod

Returns a new instance of KeyMod.

Raises:



221
222
223
224
# File 'lib/ray/dsl/matcher.rb', line 221

def initialize(name)
  raise NoKeyError, name unless Mod[name]
  @symbol = name.to_sym
end

Instance Method Details

#===(other) ⇒ Object



234
235
236
# File 'lib/ray/dsl/matcher.rb', line 234

def ===(other)
  other.is_a?(Integer) && to_a.any? { |const| (o & const) != 0 }
end

#inspectObject



238
239
240
# File 'lib/ray/dsl/matcher.rb', line 238

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

#to_aObject



226
227
228
# File 'lib/ray/dsl/matcher.rb', line 226

def to_a
  Mod[@symbol]
end

#to_symObject



230
231
232
# File 'lib/ray/dsl/matcher.rb', line 230

def to_sym
  @symbol
end