Slide 32
Slide 32 text
Anti-Patterns
Readability
Document & Test
r = some_object
POSSIBLE_VERBS = ['get', 'put', 'post', 'delete']
POSSIBLE_VERBS.each do |m|
define_method(m.to_sym) do |path, *args, &b|
r[path].public_send(m.to_sym, *args, &b)
end
end
Short != Readable
Implicit vs Explicit
r = some_object
def get(path, *args &b)
r[path].get(*args &b)
end
def put(path, *args &b)
r[path].put(*args &b)
end
def post(path, *args &b)
r[path].post(*args &b)
end
def delete(path, *args &b)
r[path].delete(*args &b)
end
Source: rest-client/rest-client
With Meta-programming Without Meta-programming