Ruby Hash and its methods

 Hi, This is Shubham Mishra from India,  this is the part of Ruby on Rails exploration journey.  In this post we will discuss about the ruby's Hash and its methods available to simplify our development and make the code more smarter 😅

Ok then without wasting a time we start looking into Ruby's Hash. If you are new to the development then you can read below or if you are aware of what is hash then you can skip to next paragraph.

Hash: Similar to array the Hash is a collection of objects but in the diffrent fashion. The hash store the items in the form of a key and its value. In short see below image, how lock can be access by the key assigned to it, similar to this only hash works.

Enough theory let jump into it with some example, One important think to remember is Hash will always take unique key, It means one key cannot be considered again in the hash.

Now i think you understood how hash works, now lets jump into some of the hash methods and how can we use it in diffrent ways. But before going ahead you may have seen some hash with keys without string, that is even possible and that is known as Symbol. Have a look into it, (In most of the time I would suggest to go with symbol since in ruby, symbol are more memory efficient than string but that is a diffrent topic, lets stick to the hash only)


Ok lets move with the code only, I think reading unnecessary things is just waist of time, we can learn a more from the code. The first we will have a look on merge



Now a day we are developing filter and sorting the list on product or other pages, so its necessary to look how can we sort a hash in ruby

In above code you may have notice that a hash's value could be a hash also. Ok now we will also look into delete methods,


Now I think enough reading, I would suggest you to open your rails terminal and play with the code! 💻

Get to know answers for common search on Google : A blog for posts which can help you for daily life problems, such as where to get free images, Topic suggestion for the blog.

Computer Science algorithms and other knowledge share : A blog for posts such as best search algorithm, Top interview questions for diffrent technologies, knowledge share for some frameworks or programming languages for the interview or in general terms.

My ideas to solve real world problems : A blog where me shared and presented my ideas to solve a real world problems, this will be interesting for me.

Future of computer science technology discussed : A blog where me discussed about the future of computer science and new technologies which will change our way for looking to solve problems.

Ruby on Rails Web development Blog : As the name suggest, it is the blog for sharing few knowledge about RoR web development framework.

Comments

Popular posts from this blog

Rails Postgresql Query timeout set and skip during migration

Rails Sync Postgresql and Elasticsearch Database of a Model

Ruby on Rails configure CORS setting with rack cors gem