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