Skip to content

Instantly share code, notes, and snippets.

@EagleEye5085
Last active April 21, 2022 15:38
Show Gist options
  • Save EagleEye5085/4e5d77962d8e85f3ac6b381eafaeb7ad to your computer and use it in GitHub Desktop.
Save EagleEye5085/4e5d77962d8e85f3ac6b381eafaeb7ad to your computer and use it in GitHub Desktop.

Hash Syntax Refactor

Fork this Gist. In your copy, refactor the Ruby Hashes below to improve readability.

foods = {
  "apples" => 23, 
  "grapes" => 507, 
  "eggs" => 48
}

person = { "height" => "6 ft", 
           "weight" => "160 lbs" 
}

post = { "image_src" => "./images/beach.png",
         "caption" => "At the beach with my besties", 
         "timestamp" => "4:37 PM August 13, 2019",
         "number_likes" => 0,
         "comments" => [] 
}

post2 = {
      "image_src" => "./images/holiday-party.png",
      "caption" => "What a great holiday party omg",
      "timestamp" => "11:37 PM December 31, 2019",
      "number_likes" => 13,
      "comments" => []
}

Since you refactored Ruby code in a Markdown file, within this file, it's impossible to know that this code is valid. What tools can you use to verify your refactored code is valid, working, Ruby code? Use that tool to verify before submitting this work. I copy/past the code in an IRB session. I ran .keys and .values for foods, person, post, post2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment