Skip to content

Instantly share code, notes, and snippets.

@sgharms
Forked from ravinggenius/http.rb
Last active December 27, 2015 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgharms/7390184 to your computer and use it in GitHub Desktop.
Save sgharms/7390184 to your computer and use it in GitHub Desktop.
# My Thoughts on Greppability
#
# The code certainly *seems* greppable but let me stress the greppability a bit.... ;)
#
# ➜ 7390184 git:(master) ✗ ack put http.rb
# :put,
#
# Comment #1
# ==========
#
# OK, it found your defining symbol. BUT Wait, a second. How likely is it that you will use the token `put` again? Let's
# say this is an HTTP library, as the class name implies. There's going to be a *TON* more 'put' Symbol matches. How will i know
# the difference between:
#
# def summon_larry
# something = complex_stuff
# something_really_long_that_gets_close_to_the_80_col_wrap_length(
# FooFrobnicator.new(something),
# :put, #<=== match!
# opts
# )
# end
#
# and
#
# [ :put, #<== match!
# :get ].each do |tok|
# define_method tok
# end
#
# COMMENT 2
# =========
#
# Neither of these says HEY STEVEN HERE'S WHERE POST IS DEFINED!
#
# BUT `def put` says exactly that! It SCREAMS it. It's the way
# tht the Pickaxe teaches us to define a method on page...5?
#
# COMMENT 3
# =========
#
# The other thing that's going to happen here is somewhere you're going to have
# to do a case statement (or something similar) a code smell in my book. I
# realize this is just a sketch, so I won't open that can of worms just yet...
#
# class HTTP
# def request(method, options)
# # stuff...
# end
#
# def get(options); request(method, options); end
# def head(options); request(method, options); end
# def put(options); request(method, options); end
# def post(options); request(method, options); end
# end
#
# ➜ 7390184 git:(master) ✗ ack put
# http.rb
# 40: def put(options); request(method, options); end
#
#
# _From the cli_:
# * I know where it's defined
# * I know its parameters (options)
# * I know what it calls
# * I know it's short!
class HTTP
def request(method, options)
# stuff...
end
[
:get,
:head,
:put,
:post
].each do |method|
define_method method do |options|
request method, options
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment