/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/ruby/ruby-511-1-008/main.rb
27 строк
596 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
class HTTPClient def method_missing(verb, path = nil, &block) verb = verb.to_s.upcase case verb when 'GET', 'POST', 'PUT', 'DELETE' request = { method: verb, path: path } block&.call(request) if block perform(request) else super end end def respond_to_missing?(name, _) %w[get post put delete].include?(name.to_s) end private def perform(req) puts "→ #{req[:method]} #{req[:path]} (body: #{req[:body]})" end end client = HTTPClient.new client.get '/users' client.post('/posts') { |r| r[:body] = { title: 'Hello' }.to_json }