Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
70
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Symbols and Hashes Intro
Intro to Symbols and Hashes
Saurabh Bhatia
April 25, 2013
Transcript
10 slides
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] }]
More Decks by Saurabh Bhatia
See All by Saurabh Bhatia
Barrister RPC
thewub
0
470
RulingOrbit
thewub
0
400
Rails API
thewub
0
460
Cloud Primer
thewub
1
420
Other Decks in Technology
See All in Technology
サーバーラックは作る時代! 3Dプリンターで作る10インチラックのススメ
jacopen
2
520
New Relicのアラート対応をClaude Codeで自動修正するワークフローを作った話
manabuseki
3
680
現場に渡し、構造で守る AI エージェントを活用したセルフサーブのデータ基盤の運用
legalontechnologies
PRO
0
120
Is the Website Dying?
miriamschwab
0
220
エンタープライズIAMについて - ID・権限をどう統制するか
oidfj
1
330
メルカリの小規模チーム「Pod」で、 エンジニアがデータアナリストなしで、 AIを使ってデータ分析の自走を目指す取り組み
jackojacko_
1
360
そのイメージ、どのCIが作った? Artifact Attestationsで来歴を固定する / Which CI system created that image? Pinning provenance with Artifact Attestations
chmikata
0
280
OCI Artifact による自動運転タクシーに向けた OTA 基盤の構築
biwashi
1
300
こんなに変わった! AWSネットワークの常識
shotashiratori
16
12k
「正しいデータ」の定義をAI エージェントとつくるGoogleADKによるデータ品質定義の実践
takaha4k
0
140
共通基盤の実装に Kotlin - Quarkus を選定した理由と採用したアーキテクチャ
nealle
1
170
成長するID管理基盤における運用もコストも犠牲にしないオブザーバビリティ向上の実践 / Improving Observability for a Growing Identity Platform Without Adding Operational Burden or Cost
kaminashi
1
140
Featured
See All Featured
[SF Ruby Conf 2025] Rails X
palkan
3
1.6k
A better future with KSS
kneath
240
18k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
630
Music & Morning Musume
bryan
48
7.5k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.6k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.3k
How to Think Like a Performance Engineer
csswizardry
28
3k
The Limits of Empathy - UXLibs8
cassininazir
2
800
Testing 201, or: Great Expectations
jmmastey
46
8.4k
Design in an AI World
tapps
1
400
Thoughts on Productivity
jonyablonski
76
5.5k
Fireside Chat
paigeccino
43
4.1k