Skip to content

Instantly share code, notes, and snippets.

@cahna
Created July 6, 2014 09:24
Show Gist options
  • Save cahna/95d4a7cba13ee1fa898f to your computer and use it in GitHub Desktop.
Save cahna/95d4a7cba13ee1fa898f to your computer and use it in GitHub Desktop.
Moonscript - read environment variable shorthand
-- Package that helper into the worlds shortest module.
-- Usage: import HOME, SHELL, EDITOR from require 'ENV'
setmetatable {}, __index: (k) => os.getenv k
-- Nifty shorthand for creating local variables from environment variables in moonscript using metatables
import HOME, SHELL, EDITOR from setmetatable {}, __index: (k) => os.getenv k
-- are both equivalent to:
HOME = os.getenv "HOME"
SHELL = os.getenv "SHELL"
EDITOR = os.getenv "EDITOR"
import HOME, SHELL, EDITOR from require 'ENV'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment