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
Equality in Ruby
Search
Romain Sempé
August 14, 2012
Programming
0
55
Equality in Ruby
Romain Sempé
August 14, 2012
Tweet
Share
More Decks by Romain Sempé
See All by Romain Sempé
Are you happy with your code quality?
rsempe
0
77
Scan security of your Rails app with Brakeman
rsempe
2
180
Other Decks in Programming
See All in Programming
JS RPCを理解する
yusukebe
5
270
TypeScript 関数型スタイルでバックエンド開発のリアル
naoya
49
16k
Enjoy Creative Coding with Ruby (RubyKaigi2024)
chobishiba
0
100
GitHub Actionsの痒いところを埋めるサードパーティーランナー
dora1998
2
260
酒飲んでたらテックリードになった話
spbaya0141
0
210
Prepare for Jakarta EE 11 - Performance and Developer Productivity
ivargrimstad
0
260
一文字エイリアスのすすめ
fujimura
0
200
Balkan Ruby 2024 — How and why to run SQLite on Rails in production
fractaledmind
0
110
Open standards for building event-driven applications in the cloud
meteatamel
0
230
Direct Style Effect Systems The Print[A] ExampleA Comprehension Aid
philipschwarz
PRO
0
410
Deep Dive into React Stream/Serialize
mugi_uno
4
860
初心者のためのRubyKaigi入門/RubyKaigi Introduction
a_matsuda
10
1.9k
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
8
3.5k
YesSQL, Process and Tooling at Scale
rocio
165
13k
The Mythical Team-Month
searls
217
42k
Into the Great Unknown - MozCon
thekraken
15
1.1k
4 Signs Your Business is Dying
shpigford
176
21k
Building a Scalable Design System with Sketch
lauravandoore
457
32k
Gamification - CAS2011
davidbonilla
77
4.6k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
Web development in the modern age
philhawksworth
203
10k
Writing Fast Ruby
sferik
622
60k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
358
22k
Building Flexible Design Systems
yeseniaperezcruz
320
37k
Transcript
Equality in Ruby Romain Sempé @rsempe
Equality or Identity? Equality: Different objects that represent the
same value. Identity: Different variables that refer to the same object.
Equal yes! But in what sense? What equality methods
should we use? == eql? equal? === =~
== Test only if the objects have the same value.
eql? Test if the objects have the same value and
the same type.
equal? Test if the objects have the same value, the
same type and are the same instance in memory.
=== Same as == but for case statements. One operator
depending on the context of the comparison (Class, Range, Regexp, …).
=~ Interesting with the Regexp class. It’s an alias to
the match method.
Conclusion == is great most of the time
eql? and equal? can be useful to be more precise Elegant case statements with === Concise test for Regexp with =~ Only one identity operator: equal?