Class: RatatuiRuby::Event::None
- Inherits:
-
RatatuiRuby::Event
- Object
- RatatuiRuby::Event
- RatatuiRuby::Event::None
- Defined in:
- lib/ratatui_ruby/event/none.rb
Overview
Null object for absent events.
Event loops poll for input 60 times per second. Usually nothing is happening. If RatatuiRuby.poll_event returned nil, you would need nil-checks: event&.key?, next unless event.
This class eliminates that friction. It responds to every predicate with false. Call none? to detect it explicitly. Pattern-match on type: :none for exhaustive dispatch.
Use it to simplify your event loop. No guards. Optional ‘else` clauses.
See Martin Fowler’s Special Case pattern.
Predicate Example
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2025 Kerrick Long SPDX-License-Identifier: MIT-0 ++
event = RatatuiRuby.poll_event
break if event.ctrl_c?
redraw if event.none?
– SPDX-SnippetEnd ++
Pattern Matching Example
redraw if RatatuiRuby.poll_event in type: :none
Instance Method Summary collapse
-
#deconstruct_keys(keys) ⇒ Object
Deconstructs the event for pattern matching.
-
#none? ⇒ Boolean
Returns true for None events.
Methods inherited from RatatuiRuby::Event
#focus_gained?, #focus_lost?, #key?, #method_missing, #mouse?, #paste?, #resize?, #respond_to_missing?, #sync?
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RatatuiRuby::Event
Instance Method Details
#deconstruct_keys(keys) ⇒ Object
Deconstructs the event for pattern matching.
48 49 50 |
# File 'lib/ratatui_ruby/event/none.rb', line 48 def deconstruct_keys(keys) { type: :none } end |
#none? ⇒ Boolean
Returns true for None events.
43 44 45 |
# File 'lib/ratatui_ruby/event/none.rb', line 43 def none? true end |