{"action":"created","comment":{"url":"https://api.github.com/repos/Shopify/measured/pulls/comments/92433936","pull_request_review_id":12947913,"id":92433936,"diff_hunk":"@@ -11,50 +11,43 @@ def initialize(base_unit, units, case_sensitive: false)\n   attr_reader :base_unit, :units\n \n   def unit_names_with_aliases\n-    @units.map{|u| u.names}.flatten.sort\n+    @unit_names_with_aliases ||= @units.flat_map(&:names).sort\n   end\n \n   def unit_names\n-    @units.map{|u| u.name}.sort\n+    @unit_names ||= @units.map(&:name).sort\n   end\n \n   def unit_or_alias?(name)\n-    @units.each{|unit| return true if unit.names_include?(name, case_sensitive: @case_sensitive)}\n-    false\n+    @units.any? { |unit| unit.names_include?(name, case_sensitive: @case_sensitive) }\n   end\n \n   def unit?(name)\n-    @units.each{|unit| return true if unit.name_eql?(name, case_sensitive: @case_sensitive)}\n-    false\n+    @units.any? { |unit| unit.name_eql?(name, case_sensitive: @case_sensitive) }\n   end\n \n   def to_unit_name(name)\n     unit_for(name).name\n   end\n \n   def convert(value, from:, to:)\n-    raise Measured::UnitError, \"Source unit #{ from } does not exits.\" unless unit?(from)\n-    raise Measured::UnitError, \"Converted unit #{ to } does not exits.\" unless unit?(to)\n-\n     from_unit = unit_for(from)\n     to_unit = unit_for(to)\n+    conversion = conversion_table[from][to]\n \n-    raise Measured::UnitError, \"Cannot find conversion entry from #{ from } to #{ to }\" unless conversion = conversion_table[from][to]\n+    raise Measured::UnitError, \"Cannot find conversion entry from #{from} to #{to}\" unless conversion\n \n     BigDecimal(value.to_r * conversion,ARBITRARY_CONVERSION_PRECISION)\n   end\n \n+  private\n+\n   def conversion_table\n     @conversion_table ||= Measured::ConversionTable.build(@units)\n   end\n \n-  private\n-\n   def unit_for(name)\n-    @units.each do |unit|\n-      return unit if unit.names_include?(name, case_sensitive: @case_sensitive)\n-    end\n-\n-    raise Measured::UnitError, \"Cannot find unit for #{ name }.\"\n+    unit = @units.find { |unit| unit.names_include?(name, case_sensitive: @case_sensitive) }\n+    unit or raise Measured::UnitError, \"Cannot find unit for #{name}\"","path":"lib/measured/conversion.rb","position":58,"original_position":58,"commit_id":"47a862b78dd98562d6ddb46975638ddae70124e3","original_commit_id":"47a862b78dd98562d6ddb46975638ddae70124e3","user":{"login":"thegedge","id":833576,"avatar_url":"https://avatars.githubusercontent.com/u/833576?v=3","gravatar_id":"","url":"https://api.github.com/users/thegedge","html_url":"https://github.com/thegedge","followers_url":"https://api.github.com/users/thegedge/followers","following_url":"https://api.github.com/users/thegedge/following{/other_user}","gists_url":"https://api.github.com/users/thegedge/gists{/gist_id}","starred_url":"https://api.github.com/users/thegedge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thegedge/subscriptions","organizations_url":"https://api.github.com/users/thegedge/orgs","repos_url":"https://api.github.com/users/thegedge/repos","events_url":"https://api.github.com/users/thegedge/events{/privacy}","received_events_url":"https://api.github.com/users/thegedge/received_events","type":"User","site_admin":false},"body":"Is this a good use of `or`? Should I use `||`? `raise unless unit` followed by `unit`?","created_at":"2016-12-14T16:38:16Z","updated_at":"2016-12-14T16:38:16Z","html_url":"https://github.com/Shopify/measured/pull/51#discussion_r92433936","pull_request_url":"https://api.github.com/repos/Shopify/measured/pulls/51","_links":{"self":{"href":"https://api.github.com/repos/Shopify/measured/pulls/comments/92433936"},"html":{"href":"https://github.com/Shopify/measured/pull/51#discussion_r92433936"},"pull_request":{"href":"https://api.github.com/repos/Shopify/measured/pulls/51"}}},"pull_request":{"url":"https://api.github.com/repos/Shopify/measured/pulls/51","id":97987931,"html_url":"https://github.com/Shopify/measured/pull/51","diff_url":"https://github.com/Shopify/measured/pull/51.diff","patch_url":"https://github.com/Shopify/measured/pull/51.patch","issue_url":"https://api.github.com/repos/Shopify/measured/issues/51","number":51,"state":"open","locked":false,"title":"Clean up the Conversion class","user":{"login":"thegedge","id":833576,"avatar_url":"https://avatars.githubusercontent.com/u/833576?v=3","gravatar_id":"","url":"https://api.github.com/users/thegedge","html_url":"https://github.com/thegedge","followers_url":"https://api.github.com/users/thegedge/followers","following_url":"https://api.github.com/users/thegedge/following{/other_user}","gists_url":"https://api.github.com/users/thegedge/gists{/gist_id}","starred_url":"https://api.github.com/users/thegedge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thegedge/subscriptions","organizations_url":"https://api.github.com/users/thegedge/orgs","repos_url":"https://api.github.com/users/thegedge/repos","events_url":"https://api.github.com/users/thegedge/events{/privacy}","received_events_url":"https://api.github.com/users/thegedge/received_events","type":"User","site_admin":false},"body":"Comments in line","created_at":"2016-12-14T16:34:07Z","updated_at":"2016-12-14T16:38:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f2c058e8d3340de4307aa5cc050028236867a980","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Shopify/measured/pulls/51/commits","review_comments_url":"https://api.github.com/repos/Shopify/measured/pulls/51/comments","review_comment_url":"https://api.github.com/repos/Shopify/measured/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Shopify/measured/issues/51/comments","statuses_url":"https://api.github.com/repos/Shopify/measured/statuses/47a862b78dd98562d6ddb46975638ddae70124e3","head":{"label":"Shopify:clean-things-up","ref":"clean-things-up","sha":"47a862b78dd98562d6ddb46975638ddae70124e3","user":{"login":"Shopify","id":8085,"avatar_url":"https://avatars.githubusercontent.com/u/8085?v=3","gravatar_id":"","url":"https://api.github.com/users/Shopify","html_url":"https://github.com/Shopify","followers_url":"https://api.github.com/users/Shopify/followers","following_url":"https://api.github.com/users/Shopify/following{/other_user}","gists_url":"https://api.github.com/users/Shopify/gists{/gist_id}","starred_url":"https://api.github.com/users/Shopify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shopify/subscriptions","organizations_url":"https://api.github.com/users/Shopify/orgs","repos_url":"https://api.github.com/users/Shopify/repos","events_url":"https://api.github.com/users/Shopify/events{/privacy}","received_events_url":"https://api.github.com/users/Shopify/received_events","type":"Organization","site_admin":false},"repo":{"id":31614166,"name":"measured","full_name":"Shopify/measured","owner":{"login":"Shopify","id":8085,"avatar_url":"https://avatars.githubusercontent.com/u/8085?v=3","gravatar_id":"","url":"https://api.github.com/users/Shopify","html_url":"https://github.com/Shopify","followers_url":"https://api.github.com/users/Shopify/followers","following_url":"https://api.github.com/users/Shopify/following{/other_user}","gists_url":"https://api.github.com/users/Shopify/gists{/gist_id}","starred_url":"https://api.github.com/users/Shopify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shopify/subscriptions","organizations_url":"https://api.github.com/users/Shopify/orgs","repos_url":"https://api.github.com/users/Shopify/repos","events_url":"https://api.github.com/users/Shopify/events{/privacy}","received_events_url":"https://api.github.com/users/Shopify/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Shopify/measured","description":"Encapsulate measurements and their units in Ruby.","fork":false,"url":"https://api.github.com/repos/Shopify/measured","forks_url":"https://api.github.com/repos/Shopify/measured/forks","keys_url":"https://api.github.com/repos/Shopify/measured/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Shopify/measured/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Shopify/measured/teams","hooks_url":"https://api.github.com/repos/Shopify/measured/hooks","issue_events_url":"https://api.github.com/repos/Shopify/measured/issues/events{/number}","events_url":"https://api.github.com/repos/Shopify/measured/events","assignees_url":"https://api.github.com/repos/Shopify/measured/assignees{/user}","branches_url":"https://api.github.com/repos/Shopify/measured/branches{/branch}","tags_url":"https://api.github.com/repos/Shopify/measured/tags","blobs_url":"https://api.github.com/repos/Shopify/measured/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Shopify/measured/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Shopify/measured/git/refs{/sha}","trees_url":"https://api.github.com/repos/Shopify/measured/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Shopify/measured/statuses/{sha}","languages_url":"https://api.github.com/repos/Shopify/measured/languages","stargazers_url":"https://api.github.com/repos/Shopify/measured/stargazers","contributors_url":"https://api.github.com/repos/Shopify/measured/contributors","subscribers_url":"https://api.github.com/repos/Shopify/measured/subscribers","subscription_url":"https://api.github.com/repos/Shopify/measured/subscription","commits_url":"https://api.github.com/repos/Shopify/measured/commits{/sha}","git_commits_url":"https://api.github.com/repos/Shopify/measured/git/commits{/sha}","comments_url":"https://api.github.com/repos/Shopify/measured/comments{/number}","issue_comment_url":"https://api.github.com/repos/Shopify/measured/issues/comments{/number}","contents_url":"https://api.github.com/repos/Shopify/measured/contents/{+path}","compare_url":"https://api.github.com/repos/Shopify/measured/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Shopify/measured/merges","archive_url":"https://api.github.com/repos/Shopify/measured/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Shopify/measured/downloads","issues_url":"https://api.github.com/repos/Shopify/measured/issues{/number}","pulls_url":"https://api.github.com/repos/Shopify/measured/pulls{/number}","milestones_url":"https://api.github.com/repos/Shopify/measured/milestones{/number}","notifications_url":"https://api.github.com/repos/Shopify/measured/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Shopify/measured/labels{/name}","releases_url":"https://api.github.com/repos/Shopify/measured/releases{/id}","deployments_url":"https://api.github.com/repos/Shopify/measured/deployments","created_at":"2015-03-03T18:29:09Z","updated_at":"2016-12-14T04:13:33Z","pushed_at":"2016-12-14T16:34:07Z","git_url":"git://github.com/Shopify/measured.git","ssh_url":"git@github.com:Shopify/measured.git","clone_url":"https://github.com/Shopify/measured.git","svn_url":"https://github.com/Shopify/measured","homepage":"","size":84,"stargazers_count":34,"watchers_count":34,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":9,"forks":3,"open_issues":9,"watchers":34,"default_branch":"master"}},"base":{"label":"Shopify:master","ref":"master","sha":"fb23b907f09dc907780f959b5b018477aa493e3b","user":{"login":"Shopify","id":8085,"avatar_url":"https://avatars.githubusercontent.com/u/8085?v=3","gravatar_id":"","url":"https://api.github.com/users/Shopify","html_url":"https://github.com/Shopify","followers_url":"https://api.github.com/users/Shopify/followers","following_url":"https://api.github.com/users/Shopify/following{/other_user}","gists_url":"https://api.github.com/users/Shopify/gists{/gist_id}","starred_url":"https://api.github.com/users/Shopify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shopify/subscriptions","organizations_url":"https://api.github.com/users/Shopify/orgs","repos_url":"https://api.github.com/users/Shopify/repos","events_url":"https://api.github.com/users/Shopify/events{/privacy}","received_events_url":"https://api.github.com/users/Shopify/received_events","type":"Organization","site_admin":false},"repo":{"id":31614166,"name":"measured","full_name":"Shopify/measured","owner":{"login":"Shopify","id":8085,"avatar_url":"https://avatars.githubusercontent.com/u/8085?v=3","gravatar_id":"","url":"https://api.github.com/users/Shopify","html_url":"https://github.com/Shopify","followers_url":"https://api.github.com/users/Shopify/followers","following_url":"https://api.github.com/users/Shopify/following{/other_user}","gists_url":"https://api.github.com/users/Shopify/gists{/gist_id}","starred_url":"https://api.github.com/users/Shopify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shopify/subscriptions","organizations_url":"https://api.github.com/users/Shopify/orgs","repos_url":"https://api.github.com/users/Shopify/repos","events_url":"https://api.github.com/users/Shopify/events{/privacy}","received_events_url":"https://api.github.com/users/Shopify/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Shopify/measured","description":"Encapsulate measurements and their units in Ruby.","fork":false,"url":"https://api.github.com/repos/Shopify/measured","forks_url":"https://api.github.com/repos/Shopify/measured/forks","keys_url":"https://api.github.com/repos/Shopify/measured/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Shopify/measured/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Shopify/measured/teams","hooks_url":"https://api.github.com/repos/Shopify/measured/hooks","issue_events_url":"https://api.github.com/repos/Shopify/measured/issues/events{/number}","events_url":"https://api.github.com/repos/Shopify/measured/events","assignees_url":"https://api.github.com/repos/Shopify/measured/assignees{/user}","branches_url":"https://api.github.com/repos/Shopify/measured/branches{/branch}","tags_url":"https://api.github.com/repos/Shopify/measured/tags","blobs_url":"https://api.github.com/repos/Shopify/measured/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Shopify/measured/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Shopify/measured/git/refs{/sha}","trees_url":"https://api.github.com/repos/Shopify/measured/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Shopify/measured/statuses/{sha}","languages_url":"https://api.github.com/repos/Shopify/measured/languages","stargazers_url":"https://api.github.com/repos/Shopify/measured/stargazers","contributors_url":"https://api.github.com/repos/Shopify/measured/contributors","subscribers_url":"https://api.github.com/repos/Shopify/measured/subscribers","subscription_url":"https://api.github.com/repos/Shopify/measured/subscription","commits_url":"https://api.github.com/repos/Shopify/measured/commits{/sha}","git_commits_url":"https://api.github.com/repos/Shopify/measured/git/commits{/sha}","comments_url":"https://api.github.com/repos/Shopify/measured/comments{/number}","issue_comment_url":"https://api.github.com/repos/Shopify/measured/issues/comments{/number}","contents_url":"https://api.github.com/repos/Shopify/measured/contents/{+path}","compare_url":"https://api.github.com/repos/Shopify/measured/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Shopify/measured/merges","archive_url":"https://api.github.com/repos/Shopify/measured/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Shopify/measured/downloads","issues_url":"https://api.github.com/repos/Shopify/measured/issues{/number}","pulls_url":"https://api.github.com/repos/Shopify/measured/pulls{/number}","milestones_url":"https://api.github.com/repos/Shopify/measured/milestones{/number}","notifications_url":"https://api.github.com/repos/Shopify/measured/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Shopify/measured/labels{/name}","releases_url":"https://api.github.com/repos/Shopify/measured/releases{/id}","deployments_url":"https://api.github.com/repos/Shopify/measured/deployments","created_at":"2015-03-03T18:29:09Z","updated_at":"2016-12-14T04:13:33Z","pushed_at":"2016-12-14T16:34:07Z","git_url":"git://github.com/Shopify/measured.git","ssh_url":"git@github.com:Shopify/measured.git","clone_url":"https://github.com/Shopify/measured.git","svn_url":"https://github.com/Shopify/measured","homepage":"","size":84,"stargazers_count":34,"watchers_count":34,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":9,"forks":3,"open_issues":9,"watchers":34,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Shopify/measured/pulls/51"},"html":{"href":"https://github.com/Shopify/measured/pull/51"},"issue":{"href":"https://api.github.com/repos/Shopify/measured/issues/51"},"comments":{"href":"https://api.github.com/repos/Shopify/measured/issues/51/comments"},"review_comments":{"href":"https://api.github.com/repos/Shopify/measured/pulls/51/comments"},"review_comment":{"href":"https://api.github.com/repos/Shopify/measured/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Shopify/measured/pulls/51/commits"},"statuses":{"href":"https://api.github.com/repos/Shopify/measured/statuses/47a862b78dd98562d6ddb46975638ddae70124e3"}}}}
{"actor":{"display_login":"thegedge"}}