Skip to content

Instantly share code, notes, and snippets.

@mkhuda
Created November 11, 2017 16:09
Show Gist options
  • Save mkhuda/c88bddaffe77c4ee3c01a2f89f8d065a to your computer and use it in GitHub Desktop.
Save mkhuda/c88bddaffe77c4ee3c01a2f89f8d065a to your computer and use it in GitHub Desktop.
Ruby Array and Hash snippets to remember
# 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