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
Model Mondays S2E02: Model Context Protocol
nitya
0
220
HiMoR: Monocular Deformable Gaussian Reconstruction with Hierarchical Motion Representation
spatial_ai_network
0
110
Github Copilot エージェントモードで試してみた
ochtum
0
100
なぜ私はいま、ここにいるのか? #もがく中堅デザイナー #プロダクトデザイナー
bengo4com
0
180
生成AIでwebアプリケーションを作ってみた
tajimon
2
150
~宇宙最速~2025年AWS Summit レポート
satodesu
1
1.8k
本が全く読めなかった過去の自分へ
genshun9
0
230
Amazon Bedrockで実現する 新たな学習体験
kzkmaeda
2
540
5min GuardDuty Extended Threat Detection EKS
takakuni
0
140
第9回情シス転職ミートアップ_テックタッチ株式会社
forester3003
0
230
25分で解説する「最小権限の原則」を実現するための AWS「ポリシー」大全 / 20250625-aws-summit-aws-policy
opelab
9
1.1k
Oracle Audit Vault and Database Firewall 20 概要
oracle4engineer
PRO
3
1.7k
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
670
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
48
5.4k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.4k
GitHub's CSS Performance
jonrohan
1031
460k
Code Review Best Practice
trishagee
68
18k
How STYLIGHT went responsive
nonsquared
100
5.6k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
124
52k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
For a Future-Friendly Web
brad_frost
179
9.8k
The Pragmatic Product Professional
lauravandoore
35
6.7k
Scaling GitHub
holman
459
140k
It's Worth the Effort
3n
185
28k
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] }]