Quantcast
Channel: Chef – cookingclouds
Viewing all articles
Browse latest Browse all 10

Hash Keys and Values in General Ruby

$
0
0

Create a new Hash

node = Hash.new

Create a new Hash of Hash

node[:one] = Hash.new

Insert Values into your Hash of Hash

node[:one][:object] = "number1"
node[:one][:block] = "number2"

Print Key and Value

node[:one].each_pair do |k,v|
  puts k
  puts v
end

Print Keys only

node[:one].keys.each do |key|
  puts key
end

Print Values Only

node[:one].values.each do |value|
  puts value
end


Viewing all articles
Browse latest Browse all 10

Trending Articles