Created
November 11, 2017 16:09
-
-
Save mkhuda/c88bddaffe77c4ee3c01a2f89f8d065a to your computer and use it in GitHub Desktop.
Ruby Array and Hash snippets to remember
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Array | |
## Manipulating element of string using squish (remove last whitespace) within array | |
Array.collect{|a| a.squish || a } | |
## Return an array values by key of hash | |
Hash.pluck(:your_key) | |
## Return an array keys from key of Hash | |
Hash.keys | |
# Hash | |
# Filtering hash by key | |
Hash.select{ |key, value| | |
key == '' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment