Alternative for Ruby singletons

Posted . Visible to the public.
require 'net/http'

module Cheat
  extend self # the magic ingredient

  def host
    @host ||= 'http://cheat.errtheblog.com/'
  end

  def http
    @http ||= Net::HTTP.start(URI.parse(host).host)
  end

  def sheet(name)
    http.get("/s/#{name}").body
  end
end

# use it
Cheat.sheet 'migrations'
Cheat.sheet 'singletons'
Last edit
License
Source code in this card is licensed under the MIT License.
Posted to makandra dev (2014-08-12 17:37)