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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Saurabh Bhatia
April 25, 2013
Technology
61
0
Share
Symbols and Hashes Intro
Intro to Symbols and Hashes
Saurabh Bhatia
April 25, 2013
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
申請待ちゼロへ!AWS × Entra IDで実現した「権限付与」のセルフサービス化
mhrtech
2
330
ぼくがかんがえたさいきょうのあうとぷっと
yama3133
0
170
"SQLは書けません"から始まる データドリブン
kubell_hr
2
460
60分で学ぶ最新Webフロントエンド
mizdra
PRO
33
17k
ネットワーク運用を楽にするAWS DevOps Agent活用法!! / 20260421 Masaki Okuda
shift_evolve
PRO
2
180
CloudSec JP #005 後締め ~ソフトウェアサプライチェーン攻撃から開発者のシークレットを守る~
lhazy
0
220
最新の脅威動向から考える、コンテナサプライチェーンのリスクと対策
kyohmizu
1
530
AIペネトレーションテスト・ セキュリティ検証「AgenticSec」ご紹介資料
laysakura
0
3.6k
レビューしきれない?それは「全て人力でのレビュー」だからではないでしょうか
amixedcolor
0
250
扱える不確実性を増やしていく - スタートアップEMが考える「任せ方」
kadoppe
0
210
Azure Static Web Apps の自動ビルドがタイムアウトしやすくなった状況に対応した件/global-azure2026
thara0402
0
350
AWS Agent Registry の基礎・概要を理解する/aws-agent-registry-intro
ren8k
1
240
Featured
See All Featured
It's Worth the Effort
3n
188
29k
BBQ
matthewcrist
89
10k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.3k
The Curse of the Amulet
leimatthew05
1
11k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
350
Code Reviewing Like a Champion
maltzj
528
40k
We Have a Design System, Now What?
morganepeng
55
8.1k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.2k
Writing Fast Ruby
sferik
630
63k
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] }]