Skip to content

Instantly share code, notes, and snippets.

@mdlawson
Created August 10, 2012 20:01
Show Gist options
  • Save mdlawson/3317391 to your computer and use it in GitHub Desktop.
Save mdlawson/3317391 to your computer and use it in GitHub Desktop.
Rogue factory
class Factory
constructor: (options) ->
@hanger = []
@entity = options.entity or Rogue.Entity
@opts = options.options or {}
@initial = options.initial
for i in [0...@initial]
@hanger.push @build()
deploy: (num) ->
if @hanger.length > 0
e = @hanger.pop()
else
e = @build()
e
build: ->
ent = new @entity @opts
ent.factory = @
ent.return = ->
@factory.hanger.push @
util.mixin @, @factory.opts
ent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment