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
36
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
430
RulingOrbit
thewub
0
370
Rails API
thewub
0
430
Cloud Primer
thewub
1
380
Other Decks in Technology
See All in Technology
20240321_生成AI時代のDevOps
kzkmaeda
2
610
コードレビューを支援するAI技術の応用
akkie76
2
140
データ品質をコード化! LINEヤフーのMLOpsを最適化する "ACP Data Quality" の紹介
lycorptech_jp
PRO
2
230
エンジニア候補者向け資料2024.03.28.pdf
macloud
0
2.9k
8週連続ウェビナー_イチから学ぶFivetran
cmsuzu
0
170
オブジェクトのおしゃべり大失敗 メッセージングアンチパターン集 / messaging anti-pattern collection
ytake
0
330
サービス成長と共に肥大化するモノレポ、長くなるCI時間 / As services grow, monorepos get bigger and CI time gets longer
kohbis
5
2.1k
ビジネスとコード品質の接合点 そしてコード品質がそこに及ぼす影響 / The Intersections of Business and Engineering, and The Impact of Code Quality There
mtx2s
10
1k
#51 “Empowering Azure Storage with RDMA”
cafenero_777
3
210
2023 Japan AWS Jr.Championsに選出されての振り返りとこれから
hiropy877
1
130
関数型DDDの理論と実践:「決定を遅らせる」を先につくり、 ビジネスの機動力と価値をあげる
knih
2
480
期待しすぎずに取り組む両面 TypeScript
shozawa
4
440
Featured
See All Featured
Designing Experiences People Love
moore
135
23k
Typedesign – Prime Four
hannesfritz
36
2k
Clear Off the Table
cherdarchuk
82
310k
Optimising Largest Contentful Paint
csswizardry
7
2.3k
Making Projects Easy
brettharned
106
5.4k
Building Adaptive Systems
keathley
29
1.8k
WebSockets: Embracing the real-time Web
robhawkes
59
6.9k
Ruby is Unlike a Banana
tanoku
95
10k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
1
3.3k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
113
18k
The Pragmatic Product Professional
lauravandoore
24
5.7k
Code Reviewing Like a Champion
maltzj
512
39k
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] }]