Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Mastering Chef

You're reading from  Mastering Chef

Product type Book
Published in Jun 2015
Publisher
ISBN-13 9781783981564
Pages 374 pages
Edition 1st Edition
Languages
Author (1):
Mayank Joshi Mayank Joshi
Profile icon Mayank Joshi

Table of Contents (20) Chapters

Mastering Chef
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Introduction to the Chef Ecosystem 2. Knife and Its Associated Plugins 3. Chef and Ruby 4. Controlling Access to Resources 5. Starting the Journey to the World of Recipes 6. Cookbooks and LWRPs 7. Roles and Environments 8. Attributes and Their Uses 9. Ohai and Its Plugin Ecosystem 10. Data Bags and Templates 11. Chef API and Search 12. Extending Chef 13. (Ab)Using Chef Index

Hashes


Hashes are also known as associative arrays, and they are dictionary-like objects, comprising keys and their associated values. Hashes are very similar to arrays; however, while arrays allow only integers to be used as an index, hashes, on the other hand, can use any object as a key.

Creating hashes

Hashes can be created easily using their implicit form as follows:

scores = { "A" => 85, "B" => 70, "C" => 60, "D" => 50, "E" => 35 }

Here, A, B, C, D, and E are keys having associated values 85, 70, 60, 50, and 35, respectively.

Hashes also allow for a form wherein keys are always symbols:

scores = { :A => 85, :B => 70, :C => 60, :D => 50, :E => 35 }

We may access each key's value using the corresponding symbol as follows:

scores[:A] #=> 85

We can also create a new hash using the new method of the Hash class:

scores = Hash.new
scores["A"] = 85

If no default value is set while creating a hash, then, when we try to access the key, it'll return nil. One can...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}