Skip to content

Instantly share code, notes, and snippets.

@pelcasandra
Created October 26, 2016 02:23
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 pelcasandra/d8efb56ca960435c57bad9e9aaca71ef to your computer and use it in GitHub Desktop.
Save pelcasandra/d8efb56ca960435c57bad9e9aaca71ef to your computer and use it in GitHub Desktop.
I want to do something like this to make a call to an API and returns the HTTParty response
MyGem.list_all
My idea is to use a format like this so I can chain methods like Mygem.list_all.submethod.
The current code goes like this
module MyGem
class << self
def list_all
@list_all ||= Get.new('list_all')
end
end
class Get
def initialize(path)
@get ||= get(path)
end
def get
HTTParty.get(url+path)
end
def submethod
...fancy stuff..
end
end
end
Problem is when I call MyGem.list_all I get #<MyGem::Get:0x007fb26d10f4b0 @get=HTTParty response... instead of directly having the HTTParty response object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment