Skip to content

Instantly share code, notes, and snippets.

@dyoder
Created November 27, 2012 00:44
Show Gist options
  • Save dyoder/4151666 to your computer and use it in GitHub Desktop.
Save dyoder/4151666 to your computer and use it in GitHub Desktop.
Using do to create a rich function
# None of the various "private" functions or data structures used by our robot function are exposed.
# The function just magically returns a robot for the given host.
robot = do ->
_makeRobot = require "robotstxt"
_userAgent = "Mozilla/5.0 (compatible; Googlebot/2.1)"
robots = {}
(host) -> robots[host] ?= _makeRobot "http://#{host}/robots.txt", _userAgent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment