I want to create an API client that has an interface similar to the active rails entry. I want consumers to be able to chain methods, and after the last method is bound, the client requests a URL based on the methods called. So this is a chaining method with some lazy rating. I looked at Active Recording , but it is very difficult (spawning processes, etc.).
Here is an example of the toy I'm talking about. You can combine as many bar methods as you like before calling get, for example:
puts Foo.bar.bar.get # => 'bar,bar'
puts Foo.bar.bar.bar.get # => 'bar,bar,bar'
I have successfully completed this, but I would not need to call the get method. So I want this:
puts Foo.bar.bar
But my current implementation does this:
puts Foo.bar.bar
, each to_s, , .
, , - , get?
:
class Bar
def get(args)
args.join(',')
end
end
class Foo < Array
def self.bar
@q = new
@q << :bar
@q
end
def bar
self << :bar
self
end
def get
Bar.new.get(self)
end
end
: Ruby Challenge -