Hashes : In Layman’s Term
Image Source: codeproject.com
One key feature of Ruby on Rails is Hashes. Now, just try to think of hashes like a PARTY. The party is a potluck occasion, naturally, each guest is required to bring an item or food. You will then need a LIST of all the guests, now this can be managed as an array. But you will also have to make a way to monitor all types of food that is being brought to the event. And to explain it further, you will want to know who is bringing the pasta, who will be bringing the fried chicken and so on. This is where Hashes come in. You will use hash to store value pairs or key pairs, this in turn will enable you to store that particular data. If for example Amanda is the “key”, and she brought cake, the variable stored and accessed by the key will be “cake”.
ルビーのシンボル、説明

イメージ提供: knowtebook.com
ルビーに関わるプログラマーの新旧関わらず、ルビーのシンボルを見ると、時々またはいつも困惑させられます。 これをスムースに行う前、慣れなくてはならないことが結構あります。 ルビー言語をについて習う人は多くの場合、ルビーオンレイルズのプロジェクトから学びます。ルビーオンレイルズではシンボルがいたるところにあります。本当にいたるところにあるのです。そのため、ルビのシンボルの概念について注意を払い、記憶することが重要になります。
ルビーのシンボルはクラスシンボルのインスタンスです。 シンボルはコロンを以下のように識別子の前につけます、":name", ":id" または":user"。 ルビーのシンボルクラスは一クラス方法を含みます。
- all_ シンボルとインスタンスの方法、 id2name、inspect、 to_i、 to_int、 to_s、 to_sym.
- all_symbols – ルビーのシンボルテーブルに全シンボルの配列を戻す。
- id2name – シンボルの文字列表現を戻す、:name.id2name は “name”を戻す。
- inspect – シンボルを文字通りに戻す。
- to_i – 各シンボルにユニークな整数を戻す。
- to_int – _i と同様
- to_s - id2name と同様
- to_sym – 特定のシンボルを一シンボルに変換する。