fork download
class SomeApi
  attr_reader :key
  def initialize(key)
    @key = key
  end

  def fetch_threads
    10.times.with_object([]) {|i,posts| posts << Post.new(self, i) }
  end

  class Post
    def initialize(parent, thread_id)
      @parent = parent
      @thread_id = thread_id
    end

    def create_post(message)
      "Posting '#{message}' to thread №#{@thread_id} apikey:#{@parent.key} "
    end
  end
end

SomeApi.new("abulik").fetch_threads.each do |post|
  puts post.create_post("sup 2ch")
end
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