Skip to content

Instantly share code, notes, and snippets.

@gbpereira
Created October 19, 2015 01:00
Show Gist options
  • Save gbpereira/5066cff8448ee5508588 to your computer and use it in GitHub Desktop.
Save gbpereira/5066cff8448ee5508588 to your computer and use it in GitHub Desktop.
# inicializando hash
hash = {} # inicializa um hash vazio
hash = Hash.new # inicializa um hash vazio
hash = {one: 1, two: 2} # inicializa um hash com valores
# adicionando valores
hash[:word] = 'seccomp'
# acessando valores
hash[:word]
#=> "seccomp"
# alterando valores
hash[:word] = 'seccomp 2015'
#=> {:one=>1, :two=>2 :seccomp=>"seccomp 2015"}
# também podem conter elementos de diferentes tipos de dados
hash = { int: 1, float: 1.0, range: (1..4), arr: [1, 2, 3], h: {a: 'a'} }
#=> => {:int=>1, :float=>1.0, :range=>1..4, :arr=>[1, 2, 3], :h=>{:a=>"a"}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment