{"action":"created","comment":{"url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/pulls/comments/232850537","pull_request_review_id":174140767,"id":232850537,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzMjg1MDUzNw==","diff_hunk":"@@ -0,0 +1,101 @@\n+# method to return a count of discrete elements contained in the form of {element => count}\n+# solution to CodeWars Kata Array#each_count\n+# frozen_string_literal: true\n+\n+# version using methods\n+class Array\n+  def count_hash\n+    each_with_object(Hash.new(0)) { |key, value| value[key] += 1 }\n+  end\n+\n+  def handle_block\n+    map { |element| yield element }.count_hash\n+  end\n+\n+  def send_method(method, *args)\n+    method_error = -> { 'Error: does not respond to given method' }\n+    map do |element|\n+      return method_error.call unless element.respond_to?(method)\n+      element.send(method, *args)\n+    end\n+    .count_hash\n+  end\n+\n+  def each_count(method = nil, *args)\n+    method_block_error = -> { 'Error: both method and block provided!' }\n+    return method_block_error.call if method && block_given?\n+    return handle_block(&Proc.new) if block_given?\n+    return count_hash if method.nil?\n+    return send_method(method, *args) if method\n+  end\n+end\n+\n+=begin\n+# version using if/elsif\n+class Array\n+  method_error = -> { 'Error: does not respond to given method' }\n+  method_block_error = -> { 'Error: both method and block provided!' }\n+  def each_count(method = nil, *args)\n+    if method && block_given?\n+      method_block_error.call\n+    elsif block_given?\n+      map { |element| yield element } .each_count\n+    elsif method.nil?\n+      each_with_object(Hash.new(0)) { |key, value| value[key] += 1 }\n+    elsif method\n+      map do |element|\n+        method_error.call unless element.respond_to?(method)\n+        element.send(method, *args)\n+      end.each_count\n+\n+    end\n+  end\n+end\n+\n+class Array\n+# version using case\n+  def each_count(method = nil, *args)\n+    method_block_error = -> { 'Error: both method and block provided!' }\n+    method_error = -> { 'Error: does not respond to given method' }\n+    case method.nil?\n+    when true\n+      case block_given?\n+      when true\n+        map { |element| yield element } .each_count\n+      when false\n+        each_with_object(Hash.new(0)) { |key, value| value[key] += 1 }\n+      end\n+    when false\n+      case block_given?\n+      when true\n+        'method_block_error.call\n+      when false\n+        map do |element|\n+          method_error.call unless element.respond_to?(method)\n+          element.send(method, *args)\n+        end.each_count\n+      end\n+    end\n+  end\n+end\n+=end\n+\n+cities = ['Melbourne', 'Dallas', 'Taipei', 'Toronto', 'Dallas', 'Kathmandu']","path":"each_count.rb","position":83,"original_position":83,"commit_id":"db0e96ef273b897fcefaa4ac839e9af6f37ef3bc","original_commit_id":"db0e96ef273b897fcefaa4ac839e9af6f37ef3bc","user":{"login":"MarinaMuttik","id":39748848,"node_id":"MDQ6VXNlcjM5NzQ4ODQ4","avatar_url":"https://avatars1.githubusercontent.com/u/39748848?v=4","gravatar_id":"","url":"https://api.github.com/users/MarinaMuttik","html_url":"https://github.com/MarinaMuttik","followers_url":"https://api.github.com/users/MarinaMuttik/followers","following_url":"https://api.github.com/users/MarinaMuttik/following{/other_user}","gists_url":"https://api.github.com/users/MarinaMuttik/gists{/gist_id}","starred_url":"https://api.github.com/users/MarinaMuttik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarinaMuttik/subscriptions","organizations_url":"https://api.github.com/users/MarinaMuttik/orgs","repos_url":"https://api.github.com/users/MarinaMuttik/repos","events_url":"https://api.github.com/users/MarinaMuttik/events{/privacy}","received_events_url":"https://api.github.com/users/MarinaMuttik/received_events","type":"User","site_admin":false},"body":"as provided in CW example so not to change","created_at":"2018-11-12T23:45:19Z","updated_at":"2018-11-12T23:45:19Z","html_url":"https://github.com/MarinaMuttik/Miscellaneous/pull/3#discussion_r232850537","pull_request_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/pulls/3","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/pulls/comments/232850537"},"html":{"href":"https://github.com/MarinaMuttik/Miscellaneous/pull/3#discussion_r232850537"},"pull_request":{"href":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/pulls/3"}},"in_reply_to_id":232850096},"pull_request":{"url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/pulls/3","id":230303165,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMwMzAzMTY1","html_url":"https://github.com/MarinaMuttik/Miscellaneous/pull/3","diff_url":"https://github.com/MarinaMuttik/Miscellaneous/pull/3.diff","patch_url":"https://github.com/MarinaMuttik/Miscellaneous/pull/3.patch","issue_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/issues/3","number":3,"state":"open","locked":false,"title":"Updateclass","user":{"login":"MarinaMuttik","id":39748848,"node_id":"MDQ6VXNlcjM5NzQ4ODQ4","avatar_url":"https://avatars1.githubusercontent.com/u/39748848?v=4","gravatar_id":"","url":"https://api.github.com/users/MarinaMuttik","html_url":"https://github.com/MarinaMuttik","followers_url":"https://api.github.com/users/MarinaMuttik/followers","following_url":"https://api.github.com/users/MarinaMuttik/following{/other_user}","gists_url":"https://api.github.com/users/MarinaMuttik/gists{/gist_id}","starred_url":"https://api.github.com/users/MarinaMuttik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarinaMuttik/subscriptions","organizations_url":"https://api.github.com/users/MarinaMuttik/orgs","repos_url":"https://api.github.com/users/MarinaMuttik/repos","events_url":"https://api.github.com/users/MarinaMuttik/events{/privacy}","received_events_url":"https://api.github.com/users/MarinaMuttik/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-11-12T23:43:02Z","updated_at":"2018-11-12T23:45:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"19b235be6570a825b52fde8aa33f359578a8eae4","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/pulls/3/commits","review_comments_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/pulls/3/comments","review_comment_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/pulls/comments{/number}","comments_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/issues/3/comments","statuses_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/statuses/db0e96ef273b897fcefaa4ac839e9af6f37ef3bc","head":{"label":"MarinaMuttik:updateclass","ref":"updateclass","sha":"db0e96ef273b897fcefaa4ac839e9af6f37ef3bc","user":{"login":"MarinaMuttik","id":39748848,"node_id":"MDQ6VXNlcjM5NzQ4ODQ4","avatar_url":"https://avatars1.githubusercontent.com/u/39748848?v=4","gravatar_id":"","url":"https://api.github.com/users/MarinaMuttik","html_url":"https://github.com/MarinaMuttik","followers_url":"https://api.github.com/users/MarinaMuttik/followers","following_url":"https://api.github.com/users/MarinaMuttik/following{/other_user}","gists_url":"https://api.github.com/users/MarinaMuttik/gists{/gist_id}","starred_url":"https://api.github.com/users/MarinaMuttik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarinaMuttik/subscriptions","organizations_url":"https://api.github.com/users/MarinaMuttik/orgs","repos_url":"https://api.github.com/users/MarinaMuttik/repos","events_url":"https://api.github.com/users/MarinaMuttik/events{/privacy}","received_events_url":"https://api.github.com/users/MarinaMuttik/received_events","type":"User","site_admin":false},"repo":{"id":153162834,"node_id":"MDEwOlJlcG9zaXRvcnkxNTMxNjI4MzQ=","name":"Miscellaneous","full_name":"MarinaMuttik/Miscellaneous","private":false,"owner":{"login":"MarinaMuttik","id":39748848,"node_id":"MDQ6VXNlcjM5NzQ4ODQ4","avatar_url":"https://avatars1.githubusercontent.com/u/39748848?v=4","gravatar_id":"","url":"https://api.github.com/users/MarinaMuttik","html_url":"https://github.com/MarinaMuttik","followers_url":"https://api.github.com/users/MarinaMuttik/followers","following_url":"https://api.github.com/users/MarinaMuttik/following{/other_user}","gists_url":"https://api.github.com/users/MarinaMuttik/gists{/gist_id}","starred_url":"https://api.github.com/users/MarinaMuttik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarinaMuttik/subscriptions","organizations_url":"https://api.github.com/users/MarinaMuttik/orgs","repos_url":"https://api.github.com/users/MarinaMuttik/repos","events_url":"https://api.github.com/users/MarinaMuttik/events{/privacy}","received_events_url":"https://api.github.com/users/MarinaMuttik/received_events","type":"User","site_admin":false},"html_url":"https://github.com/MarinaMuttik/Miscellaneous","description":"Ruby Testing","fork":false,"url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous","forks_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/forks","keys_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/teams","hooks_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/hooks","issue_events_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/issues/events{/number}","events_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/events","assignees_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/assignees{/user}","branches_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/branches{/branch}","tags_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/tags","blobs_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/git/refs{/sha}","trees_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/statuses/{sha}","languages_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/languages","stargazers_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/stargazers","contributors_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/contributors","subscribers_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/subscribers","subscription_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/subscription","commits_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/commits{/sha}","git_commits_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/git/commits{/sha}","comments_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/comments{/number}","issue_comment_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/issues/comments{/number}","contents_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/contents/{+path}","compare_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/merges","archive_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/downloads","issues_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/issues{/number}","pulls_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/pulls{/number}","milestones_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/milestones{/number}","notifications_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/labels{/name}","releases_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/releases{/id}","deployments_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/deployments","created_at":"2018-10-15T18:32:33Z","updated_at":"2018-10-25T14:18:31Z","pushed_at":"2018-11-12T23:43:03Z","git_url":"git://github.com/MarinaMuttik/Miscellaneous.git","ssh_url":"git@github.com:MarinaMuttik/Miscellaneous.git","clone_url":"https://github.com/MarinaMuttik/Miscellaneous.git","svn_url":"https://github.com/MarinaMuttik/Miscellaneous","homepage":null,"size":26,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"MarinaMuttik:master","ref":"master","sha":"80ac17558a5c8d1fb868524109abf0e239196342","user":{"login":"MarinaMuttik","id":39748848,"node_id":"MDQ6VXNlcjM5NzQ4ODQ4","avatar_url":"https://avatars1.githubusercontent.com/u/39748848?v=4","gravatar_id":"","url":"https://api.github.com/users/MarinaMuttik","html_url":"https://github.com/MarinaMuttik","followers_url":"https://api.github.com/users/MarinaMuttik/followers","following_url":"https://api.github.com/users/MarinaMuttik/following{/other_user}","gists_url":"https://api.github.com/users/MarinaMuttik/gists{/gist_id}","starred_url":"https://api.github.com/users/MarinaMuttik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarinaMuttik/subscriptions","organizations_url":"https://api.github.com/users/MarinaMuttik/orgs","repos_url":"https://api.github.com/users/MarinaMuttik/repos","events_url":"https://api.github.com/users/MarinaMuttik/events{/privacy}","received_events_url":"https://api.github.com/users/MarinaMuttik/received_events","type":"User","site_admin":false},"repo":{"id":153162834,"node_id":"MDEwOlJlcG9zaXRvcnkxNTMxNjI4MzQ=","name":"Miscellaneous","full_name":"MarinaMuttik/Miscellaneous","private":false,"owner":{"login":"MarinaMuttik","id":39748848,"node_id":"MDQ6VXNlcjM5NzQ4ODQ4","avatar_url":"https://avatars1.githubusercontent.com/u/39748848?v=4","gravatar_id":"","url":"https://api.github.com/users/MarinaMuttik","html_url":"https://github.com/MarinaMuttik","followers_url":"https://api.github.com/users/MarinaMuttik/followers","following_url":"https://api.github.com/users/MarinaMuttik/following{/other_user}","gists_url":"https://api.github.com/users/MarinaMuttik/gists{/gist_id}","starred_url":"https://api.github.com/users/MarinaMuttik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarinaMuttik/subscriptions","organizations_url":"https://api.github.com/users/MarinaMuttik/orgs","repos_url":"https://api.github.com/users/MarinaMuttik/repos","events_url":"https://api.github.com/users/MarinaMuttik/events{/privacy}","received_events_url":"https://api.github.com/users/MarinaMuttik/received_events","type":"User","site_admin":false},"html_url":"https://github.com/MarinaMuttik/Miscellaneous","description":"Ruby Testing","fork":false,"url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous","forks_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/forks","keys_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/teams","hooks_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/hooks","issue_events_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/issues/events{/number}","events_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/events","assignees_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/assignees{/user}","branches_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/branches{/branch}","tags_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/tags","blobs_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/git/refs{/sha}","trees_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/statuses/{sha}","languages_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/languages","stargazers_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/stargazers","contributors_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/contributors","subscribers_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/subscribers","subscription_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/subscription","commits_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/commits{/sha}","git_commits_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/git/commits{/sha}","comments_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/comments{/number}","issue_comment_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/issues/comments{/number}","contents_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/contents/{+path}","compare_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/merges","archive_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/downloads","issues_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/issues{/number}","pulls_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/pulls{/number}","milestones_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/milestones{/number}","notifications_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/labels{/name}","releases_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/releases{/id}","deployments_url":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/deployments","created_at":"2018-10-15T18:32:33Z","updated_at":"2018-10-25T14:18:31Z","pushed_at":"2018-11-12T23:43:03Z","git_url":"git://github.com/MarinaMuttik/Miscellaneous.git","ssh_url":"git@github.com:MarinaMuttik/Miscellaneous.git","clone_url":"https://github.com/MarinaMuttik/Miscellaneous.git","svn_url":"https://github.com/MarinaMuttik/Miscellaneous","homepage":null,"size":26,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/pulls/3"},"html":{"href":"https://github.com/MarinaMuttik/Miscellaneous/pull/3"},"issue":{"href":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/issues/3"},"comments":{"href":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/MarinaMuttik/Miscellaneous/statuses/db0e96ef273b897fcefaa4ac839e9af6f37ef3bc"}},"author_association":"OWNER"}}
{"actor":{"display_login":"MarinaMuttik"}}