Skip to content

Instantly share code, notes, and snippets.

@hogelog
Created March 13, 2022 11:30
Show Gist options
  • Save hogelog/f9166d7b297af15e15481993e356ecc4 to your computer and use it in GitHub Desktop.
Save hogelog/f9166d7b297af15e15481993e356ecc4 to your computer and use it in GitHub Desktop.
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