{"action":"created","comment":{"url":"https://api.github.com/repos/manastech/crystal/pulls/comments/39979063","id":39979063,"diff_hunk":"@@ -52,6 +47,31 @@ module ENV\n     !!LibC.getenv(key)\n   end\n \n+  # Retrieve a value corresponding to a key. Raises a KeyError exception if the\n+  # key does not exist.\n+  #\n+  def self.fetch(key)\n+    fetch(key) do\n+      raise KeyError.new \"Missing ENV key: #{key.inspect}\"\n+    end\n+  end\n+\n+  # Retrieve a value corresponding to a key. Return the second argument's value\n+  # if the key does not exist.\n+  #\n+  def self.fetch(key, default)\n+    fetch(key) { default }\n+  end\n+\n+  # Retrieve a value corresponding to a key. Return the value of the block if\n+  # the key does not exist.\n+  #\n+  def self.fetch(key)\n+    value = self[key]?\n+    return value if value\n+    yield(key).to_s","path":"src/env.cr","position":40,"original_position":40,"commit_id":"250abb29ec0a8196b6a13834e80665092571cbfb","original_commit_id":"250abb29ec0a8196b6a13834e80665092571cbfb","user":{"login":"tristil","id":15716,"avatar_url":"https://avatars.githubusercontent.com/u/15716?v=3","gravatar_id":"","url":"https://api.github.com/users/tristil","html_url":"https://github.com/tristil","followers_url":"https://api.github.com/users/tristil/followers","following_url":"https://api.github.com/users/tristil/following{/other_user}","gists_url":"https://api.github.com/users/tristil/gists{/gist_id}","starred_url":"https://api.github.com/users/tristil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tristil/subscriptions","organizations_url":"https://api.github.com/users/tristil/orgs","repos_url":"https://api.github.com/users/tristil/repos","events_url":"https://api.github.com/users/tristil/events{/privacy}","received_events_url":"https://api.github.com/users/tristil/received_events","type":"User","site_admin":false},"body":"Ah interesting. I like the type restriction option a lot. Totally new way to think for me.","created_at":"2015-09-21T14:48:02Z","updated_at":"2015-09-21T14:48:02Z","html_url":"https://github.com/manastech/crystal/pull/1533#discussion_r39979063","pull_request_url":"https://api.github.com/repos/manastech/crystal/pulls/1533","_links":{"self":{"href":"https://api.github.com/repos/manastech/crystal/pulls/comments/39979063"},"html":{"href":"https://github.com/manastech/crystal/pull/1533#discussion_r39979063"},"pull_request":{"href":"https://api.github.com/repos/manastech/crystal/pulls/1533"}}},"pull_request":{"url":"https://api.github.com/repos/manastech/crystal/pulls/1533","id":45491497,"html_url":"https://github.com/manastech/crystal/pull/1533","diff_url":"https://github.com/manastech/crystal/pull/1533.diff","patch_url":"https://github.com/manastech/crystal/pull/1533.patch","issue_url":"https://api.github.com/repos/manastech/crystal/issues/1533","number":1533,"state":"open","locked":false,"title":"Add .fetch to ENV","user":{"login":"tristil","id":15716,"avatar_url":"https://avatars.githubusercontent.com/u/15716?v=3","gravatar_id":"","url":"https://api.github.com/users/tristil","html_url":"https://github.com/tristil","followers_url":"https://api.github.com/users/tristil/followers","following_url":"https://api.github.com/users/tristil/following{/other_user}","gists_url":"https://api.github.com/users/tristil/gists{/gist_id}","starred_url":"https://api.github.com/users/tristil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tristil/subscriptions","organizations_url":"https://api.github.com/users/tristil/orgs","repos_url":"https://api.github.com/users/tristil/repos","events_url":"https://api.github.com/users/tristil/events{/privacy}","received_events_url":"https://api.github.com/users/tristil/received_events","type":"User","site_admin":false},"body":"Adds a fetch method to ENV with same interface as Hash#fetch.","created_at":"2015-09-20T07:21:01Z","updated_at":"2015-09-21T14:48:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3672b199a14a7b00502d25e609d34fb9774ef8a0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/manastech/crystal/pulls/1533/commits","review_comments_url":"https://api.github.com/repos/manastech/crystal/pulls/1533/comments","review_comment_url":"https://api.github.com/repos/manastech/crystal/pulls/comments{/number}","comments_url":"https://api.github.com/repos/manastech/crystal/issues/1533/comments","statuses_url":"https://api.github.com/repos/manastech/crystal/statuses/250abb29ec0a8196b6a13834e80665092571cbfb","head":{"label":"tristil:env_fetch","ref":"env_fetch","sha":"250abb29ec0a8196b6a13834e80665092571cbfb","user":{"login":"tristil","id":15716,"avatar_url":"https://avatars.githubusercontent.com/u/15716?v=3","gravatar_id":"","url":"https://api.github.com/users/tristil","html_url":"https://github.com/tristil","followers_url":"https://api.github.com/users/tristil/followers","following_url":"https://api.github.com/users/tristil/following{/other_user}","gists_url":"https://api.github.com/users/tristil/gists{/gist_id}","starred_url":"https://api.github.com/users/tristil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tristil/subscriptions","organizations_url":"https://api.github.com/users/tristil/orgs","repos_url":"https://api.github.com/users/tristil/repos","events_url":"https://api.github.com/users/tristil/events{/privacy}","received_events_url":"https://api.github.com/users/tristil/received_events","type":"User","site_admin":false},"repo":{"id":42701865,"name":"crystal","full_name":"tristil/crystal","owner":{"login":"tristil","id":15716,"avatar_url":"https://avatars.githubusercontent.com/u/15716?v=3","gravatar_id":"","url":"https://api.github.com/users/tristil","html_url":"https://github.com/tristil","followers_url":"https://api.github.com/users/tristil/followers","following_url":"https://api.github.com/users/tristil/following{/other_user}","gists_url":"https://api.github.com/users/tristil/gists{/gist_id}","starred_url":"https://api.github.com/users/tristil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tristil/subscriptions","organizations_url":"https://api.github.com/users/tristil/orgs","repos_url":"https://api.github.com/users/tristil/repos","events_url":"https://api.github.com/users/tristil/events{/privacy}","received_events_url":"https://api.github.com/users/tristil/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tristil/crystal","description":"The Crystal Programming Language","fork":true,"url":"https://api.github.com/repos/tristil/crystal","forks_url":"https://api.github.com/repos/tristil/crystal/forks","keys_url":"https://api.github.com/repos/tristil/crystal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tristil/crystal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tristil/crystal/teams","hooks_url":"https://api.github.com/repos/tristil/crystal/hooks","issue_events_url":"https://api.github.com/repos/tristil/crystal/issues/events{/number}","events_url":"https://api.github.com/repos/tristil/crystal/events","assignees_url":"https://api.github.com/repos/tristil/crystal/assignees{/user}","branches_url":"https://api.github.com/repos/tristil/crystal/branches{/branch}","tags_url":"https://api.github.com/repos/tristil/crystal/tags","blobs_url":"https://api.github.com/repos/tristil/crystal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tristil/crystal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tristil/crystal/git/refs{/sha}","trees_url":"https://api.github.com/repos/tristil/crystal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tristil/crystal/statuses/{sha}","languages_url":"https://api.github.com/repos/tristil/crystal/languages","stargazers_url":"https://api.github.com/repos/tristil/crystal/stargazers","contributors_url":"https://api.github.com/repos/tristil/crystal/contributors","subscribers_url":"https://api.github.com/repos/tristil/crystal/subscribers","subscription_url":"https://api.github.com/repos/tristil/crystal/subscription","commits_url":"https://api.github.com/repos/tristil/crystal/commits{/sha}","git_commits_url":"https://api.github.com/repos/tristil/crystal/git/commits{/sha}","comments_url":"https://api.github.com/repos/tristil/crystal/comments{/number}","issue_comment_url":"https://api.github.com/repos/tristil/crystal/issues/comments{/number}","contents_url":"https://api.github.com/repos/tristil/crystal/contents/{+path}","compare_url":"https://api.github.com/repos/tristil/crystal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tristil/crystal/merges","archive_url":"https://api.github.com/repos/tristil/crystal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tristil/crystal/downloads","issues_url":"https://api.github.com/repos/tristil/crystal/issues{/number}","pulls_url":"https://api.github.com/repos/tristil/crystal/pulls{/number}","milestones_url":"https://api.github.com/repos/tristil/crystal/milestones{/number}","notifications_url":"https://api.github.com/repos/tristil/crystal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tristil/crystal/labels{/name}","releases_url":"https://api.github.com/repos/tristil/crystal/releases{/id}","created_at":"2015-09-18T05:36:07Z","updated_at":"2015-09-18T05:36:09Z","pushed_at":"2015-09-20T22:48:58Z","git_url":"git://github.com/tristil/crystal.git","ssh_url":"git@github.com:tristil/crystal.git","clone_url":"https://github.com/tristil/crystal.git","svn_url":"https://github.com/tristil/crystal","homepage":"http://crystal-lang.org","size":31419,"stargazers_count":0,"watchers_count":0,"language":"Crystal","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"manastech:master","ref":"master","sha":"124e1b194990e74cac8934ddbf92806e988af314","user":{"login":"manastech","id":1354950,"avatar_url":"https://avatars.githubusercontent.com/u/1354950?v=3","gravatar_id":"","url":"https://api.github.com/users/manastech","html_url":"https://github.com/manastech","followers_url":"https://api.github.com/users/manastech/followers","following_url":"https://api.github.com/users/manastech/following{/other_user}","gists_url":"https://api.github.com/users/manastech/gists{/gist_id}","starred_url":"https://api.github.com/users/manastech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manastech/subscriptions","organizations_url":"https://api.github.com/users/manastech/orgs","repos_url":"https://api.github.com/users/manastech/repos","events_url":"https://api.github.com/users/manastech/events{/privacy}","received_events_url":"https://api.github.com/users/manastech/received_events","type":"Organization","site_admin":false},"repo":{"id":6887813,"name":"crystal","full_name":"manastech/crystal","owner":{"login":"manastech","id":1354950,"avatar_url":"https://avatars.githubusercontent.com/u/1354950?v=3","gravatar_id":"","url":"https://api.github.com/users/manastech","html_url":"https://github.com/manastech","followers_url":"https://api.github.com/users/manastech/followers","following_url":"https://api.github.com/users/manastech/following{/other_user}","gists_url":"https://api.github.com/users/manastech/gists{/gist_id}","starred_url":"https://api.github.com/users/manastech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manastech/subscriptions","organizations_url":"https://api.github.com/users/manastech/orgs","repos_url":"https://api.github.com/users/manastech/repos","events_url":"https://api.github.com/users/manastech/events{/privacy}","received_events_url":"https://api.github.com/users/manastech/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/manastech/crystal","description":"The Crystal Programming Language","fork":false,"url":"https://api.github.com/repos/manastech/crystal","forks_url":"https://api.github.com/repos/manastech/crystal/forks","keys_url":"https://api.github.com/repos/manastech/crystal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/manastech/crystal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/manastech/crystal/teams","hooks_url":"https://api.github.com/repos/manastech/crystal/hooks","issue_events_url":"https://api.github.com/repos/manastech/crystal/issues/events{/number}","events_url":"https://api.github.com/repos/manastech/crystal/events","assignees_url":"https://api.github.com/repos/manastech/crystal/assignees{/user}","branches_url":"https://api.github.com/repos/manastech/crystal/branches{/branch}","tags_url":"https://api.github.com/repos/manastech/crystal/tags","blobs_url":"https://api.github.com/repos/manastech/crystal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/manastech/crystal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/manastech/crystal/git/refs{/sha}","trees_url":"https://api.github.com/repos/manastech/crystal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/manastech/crystal/statuses/{sha}","languages_url":"https://api.github.com/repos/manastech/crystal/languages","stargazers_url":"https://api.github.com/repos/manastech/crystal/stargazers","contributors_url":"https://api.github.com/repos/manastech/crystal/contributors","subscribers_url":"https://api.github.com/repos/manastech/crystal/subscribers","subscription_url":"https://api.github.com/repos/manastech/crystal/subscription","commits_url":"https://api.github.com/repos/manastech/crystal/commits{/sha}","git_commits_url":"https://api.github.com/repos/manastech/crystal/git/commits{/sha}","comments_url":"https://api.github.com/repos/manastech/crystal/comments{/number}","issue_comment_url":"https://api.github.com/repos/manastech/crystal/issues/comments{/number}","contents_url":"https://api.github.com/repos/manastech/crystal/contents/{+path}","compare_url":"https://api.github.com/repos/manastech/crystal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/manastech/crystal/merges","archive_url":"https://api.github.com/repos/manastech/crystal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/manastech/crystal/downloads","issues_url":"https://api.github.com/repos/manastech/crystal/issues{/number}","pulls_url":"https://api.github.com/repos/manastech/crystal/pulls{/number}","milestones_url":"https://api.github.com/repos/manastech/crystal/milestones{/number}","notifications_url":"https://api.github.com/repos/manastech/crystal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/manastech/crystal/labels{/name}","releases_url":"https://api.github.com/repos/manastech/crystal/releases{/id}","created_at":"2012-11-27T17:32:32Z","updated_at":"2015-09-21T14:12:19Z","pushed_at":"2015-09-21T14:46:24Z","git_url":"git://github.com/manastech/crystal.git","ssh_url":"git@github.com:manastech/crystal.git","clone_url":"https://github.com/manastech/crystal.git","svn_url":"https://github.com/manastech/crystal","homepage":"http://crystal-lang.org","size":45754,"stargazers_count":3378,"watchers_count":3378,"language":"Crystal","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":251,"mirror_url":null,"open_issues_count":232,"forks":251,"open_issues":232,"watchers":3378,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/manastech/crystal/pulls/1533"},"html":{"href":"https://github.com/manastech/crystal/pull/1533"},"issue":{"href":"https://api.github.com/repos/manastech/crystal/issues/1533"},"comments":{"href":"https://api.github.com/repos/manastech/crystal/issues/1533/comments"},"review_comments":{"href":"https://api.github.com/repos/manastech/crystal/pulls/1533/comments"},"review_comment":{"href":"https://api.github.com/repos/manastech/crystal/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/manastech/crystal/pulls/1533/commits"},"statuses":{"href":"https://api.github.com/repos/manastech/crystal/statuses/250abb29ec0a8196b6a13834e80665092571cbfb"}}}}