Created
October 26, 2016 02:23
-
-
Save pelcasandra/d8efb56ca960435c57bad9e9aaca71ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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