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
56
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
190
Other Decks in Programming
See All in Programming
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
200
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
1k
イマのCSSでできる インタラクション最前線 + CSS最新情報
clockmaker
3
440
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
受け取る人から提供する人になるということ
little_rubyist
0
250
初めてDefinitelyTypedにPRを出した話
syumai
0
420
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
300
subpath importsで始めるモック生活
10tera
0
320
Ethereum_.pdf
nekomatu
0
470
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
136
6.6k
Git: the NoSQL Database
bkeepers
PRO
427
64k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Bash Introduction
62gerente
608
210k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Facilitating Awesome Meetings
lara
50
6.1k
Side Projects
sachag
452
42k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Optimizing for Happiness
mojombo
376
70k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
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?