Skip to content

Instantly share code, notes, and snippets.

@tommi-lew
Last active October 6, 2015 06:38
Show Gist options
  • Save tommi-lew/2952154 to your computer and use it in GitHub Desktop.
Save tommi-lew/2952154 to your computer and use it in GitHub Desktop.
Generate RESTful URLs by using Ruby's method missing
class Client
attr_accessor :calls
def get()
api = "http://www.cslew.com/api/"
request = ""
@calls.each do |c|
request += "#{c.keys[0]}/"
request += "#{c.values[0]}/" if c.values[0] != []
end
api + request
end
protected
def method_missing(name, *args, &block)
@calls = [] if @calls == nil
@calls.push({ name => args })
self
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment