Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
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
55
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
380
Rails API
thewub
0
430
Cloud Primer
thewub
1
410
Other Decks in Technology
See All in Technology
OCIjp_Oracle AI World_Recap
shinpy
1
150
「改善」ってこれでいいんだっけ?
ukigmo_hiro
0
390
会社を支える Pythonという言語戦略 ~なぜPythonを主要言語にしているのか?~
curekoshimizu
1
240
現場データから見える、開発生産性の変化コード生成AI導入・運用のリアル〜 / Changes in Development Productivity and Operational Challenges Following the Introduction of Code Generation AI
nttcom
1
420
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
12
81k
研究開発部メンバーの働き⽅ / Sansan R&D Profile
sansan33
PRO
3
20k
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
940
生成AI時代のセキュアコーディングとDevSecOps
yuriemori
0
140
LLMプロダクトの信頼性を上げるには?LLM Observabilityによる、対話型音声AIアプリケーションの安定運用
ivry_presentationmaterials
0
740
旅で応援する✈️ NEWTが目指すコミュニティ支援とあたらしい旅行 / New Travel: Supporting by NEWT on Your Journey
mii3king
0
110
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.2k
Introdução a Service Mesh usando o Istio
aeciopires
1
260
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.5k
It's Worth the Effort
3n
187
28k
KATA
mclloyd
PRO
32
15k
Done Done
chrislema
185
16k
The Illustrated Children's Guide to Kubernetes
chrisshort
49
51k
BBQ
matthewcrist
89
9.8k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
The Cult of Friendly URLs
andyhume
79
6.6k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
630
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
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] }]