Created
March 13, 2022 11:30
-
-
Save hogelog/f9166d7b297af15e15481993e356ecc4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReplaceWords | |
attr_reader :app | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
binding.irb | |
http_status_code, headers, body = @app.call(env) | |
return [http_status_code, headers, body.map { _1.gsub!(/ruby/i, 'rack') }] | |
end | |
end | |
class UpperWords | |
attr_reader :app | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
binding.irb | |
http_status_code, headers, body = @app.call(env) | |
return [http_status_code, headers, body.map { _1.upcase }] | |
end | |
end | |
class App | |
attr_reader :app | |
def call(env) | |
binding.irb | |
[200, {'Content-Type' => 'text/html'}, ['Hello, Ruby world!']] | |
end | |
end | |
use UpperWords | |
use ReplaceWords | |
binding.irb | |
run App.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment