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, &callback)
  20. (1..10).each do |i|
  21. yield klass.new(self, i) if callback
  22. end
  23. end
  24. end
  25.  
  26. SomeApi.new("abulik").fetch_threads(Post) do |post|
  27. puts post.create_post("sup 2ch")
  28. end
  29.  
Success #stdin #stdout 0.02s 9784KB
stdin
Standard input is empty
stdout
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 
Posting 'sup 2ch' to thread №10 apikey:abulik