fork download
  1. class SomeApi
  2. attr_reader :key
  3. def initialize(key)
  4. @key = key
  5. end
  6.  
  7. def fetch_threads
  8. 10.times.with_object([]) {|i,posts| posts << Post.new(self, i) }
  9. end
  10.  
  11. class Post
  12. def initialize(parent, thread_id)
  13. @parent = parent
  14. @thread_id = thread_id
  15. end
  16.  
  17. def create_post(message)
  18. "Posting '#{message}' to thread №#{@thread_id} apikey:#{@parent.key} "
  19. end
  20. end
  21. end
  22.  
  23. SomeApi.new("abulik").fetch_threads.each do |post|
  24. puts post.create_post("sup 2ch")
  25. end
  26.  
Success #stdin #stdout 0.03s 9776KB
stdin
Standard input is empty
stdout
Posting 'sup 2ch' to thread №0 apikey:abulik 
Posting 'sup 2ch' to thread №1 apikey:abulik 
Posting 'sup 2ch' to thread №2 apikey:abulik 
Posting 'sup 2ch' to thread №3 apikey:abulik 
Posting 'sup 2ch' to thread №4 apikey:abulik 
Posting 'sup 2ch' to thread №5 apikey:abulik 
Posting 'sup 2ch' to thread №6 apikey:abulik 
Posting 'sup 2ch' to thread №7 apikey:abulik 
Posting 'sup 2ch' to thread №8 apikey:abulik 
Posting 'sup 2ch' to thread №9 apikey:abulik