Class: Bane::Behaviors::SlowResponse
- Inherits:
-
BasicBehavior
- Object
- BasicBehavior
- Bane::Behaviors::SlowResponse
- Defined in:
- lib/bane/behaviors.rb
Overview
Sends a fixed response character-by-character, pausing between each character.
Options:
- message: The response to send. Default: "Hello, world!"
- pause_duration: The number of seconds to pause between each character. Default: 10 seconds
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ SlowResponse
constructor
A new instance of SlowResponse.
- #serve(io) ⇒ Object
Methods inherited from BasicBehavior
Constructor Details
#initialize(options = {}) ⇒ SlowResponse
Returns a new instance of SlowResponse.
99 100 101 |
# File 'lib/bane/behaviors.rb', line 99 def initialize( = {}) @options = {:message => "Hello, world!", :pause_duration => 10}.merge() end |
Instance Method Details
#serve(io) ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'lib/bane/behaviors.rb', line 103 def serve(io) = @options[:message] pause_duration = @options[:pause_duration] .each_char do |char| io.write char sleep pause_duration end end |