Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Symbols and Hashes Intro
Search
Saurabh Bhatia
April 25, 2013
Technology
0
56
Symbols and Hashes Intro
Intro to Symbols and Hashes
Saurabh Bhatia
April 25, 2013
Tweet
Share
More Decks by Saurabh Bhatia
See All by Saurabh Bhatia
Barrister RPC
thewub
0
450
RulingOrbit
thewub
0
390
Rails API
thewub
0
440
Cloud Primer
thewub
1
410
Other Decks in Technology
See All in Technology
ガバメントクラウド利用システムのライフサイクルについて
techniczna
0
190
学習データって増やせばいいんですか?
ftakahashi
2
330
Reinforcement Fine-tuning 基礎〜実践まで
ch6noota
0
180
EM歴1年10ヶ月のぼくがぶち当たった苦悩とこれからへ向けて
maaaato
0
280
コンテキスト情報を活用し個社最適化されたAI Agentを実現する4つのポイント
kworkdev
PRO
0
1.2k
世界最速級 memcached 互換サーバー作った
yasukata
0
340
SSO方式とJumpアカウント方式の比較と設計方針
yuobayashi
7
670
生成AIでテスト設計はどこまでできる? 「テスト粒度」を操るテーラリング術
shota_kusaba
0
760
寫了幾年 Code,然後呢?軟體工程師必須重新認識的 DevOps
cheng_wei_chen
1
1.4k
Snowflakeでデータ基盤を もう一度作り直すなら / rebuilding-data-platform-with-snowflake
pei0804
5
1.5k
AIプラットフォームにおけるMLflowの利用について
lycorptech_jp
PRO
1
140
WordPress は終わったのか ~今のWordPress の制作手法ってなにがあんねん?~ / Is WordPress Over? How We Build with WordPress Today
tbshiki
1
760
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.6k
Balancing Empowerment & Direction
lara
5
800
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
14k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.8k
Visualization
eitanlees
150
16k
Music & Morning Musume
bryan
46
7k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
How to Ace a Technical Interview
jacobian
280
24k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
Designing Experiences People Love
moore
143
24k
Being A Developer After 40
akosma
91
590k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
Transcript
Strings and Hashes
What is it ? • Symbol is something used to
represent a string. • A more memory efficient and descriptive way to do things.
How does it look ? Colon followed by a non-quoted
string - :symbol Or Colon followed by quoted string - :'this is another symbol'
Assigning stuff to symbols • :my_symbol = “foo_bar” - wrong
• my_symbol = :foo_bar – right • attr_accessor :foo_bar • my_symbol = :foo_bar.to_s
Symbols are immutable
hash • Data structure – collection of key value pairs
• Indexing via keys of object _type • Randomly ordered
What does it look like ? • animals = Hash.new
• animals["dog"] = "bark" • pry(main)> animals => {"dog"=>"bark", "cat"=>"purr"}
• Iterating over an array • animal_farm.each do |a| puts
a end • Iterating over a hash • animals.each do |k,v| puts “#{k} and #{v} end
exercise • Create a hash to represent currencies eg USA
=> usd , UK => gbp, JAPAN => yen • Display all the currencies • Replace all the name of countries with their short codes eg US -> US, JAPAN –> JP, UK -> UK
Solution • currencies = { “USA” => “usd” , “UK”
=> “gbp”, “JAPAN” => “yen” } • new_currencies = {"US" => "usd", "UK" => "gbp", “JP” => “yen”} • Hash[currencies.map {|k, v| [new_currencies[k], v] }]