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
Ruby Trivia 3
Search
Erik Berlin
December 03, 2015
Programming
0
650
Ruby Trivia 3
Presented at the Berlin Ruby User Group (RUG::B) on November 5, 2015.
Erik Berlin
December 03, 2015
Tweet
Share
More Decks by Erik Berlin
See All by Erik Berlin
Enumerator::Lazy
sferik
1
510
The Value of Being Lazy
sferik
3
700
Ruby Trivia 2
sferik
0
690
Ruby Trivia
sferik
2
1.2k
💀 Symbols
sferik
5
1.8k
Content Negotiation for REST APIs
sferik
8
930
Writing Fast Ruby
sferik
628
61k
Mutation Testing with Mutant
sferik
5
1.1k
Other Decks in Programming
See All in Programming
採用事例の少ないSvelteを選んだ理由と それを正解にするためにやっていること
oekazuma
2
1k
バグを見つけた?それAppleに直してもらおう!
uetyo
0
170
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
ソフトウェアの振る舞いに着目し 複雑な要件の開発に立ち向かう
rickyban
0
890
命名をリントする
chiroruxx
1
380
CSC305 Lecture 26
javiergs
PRO
0
140
103 Early Hints
sugi_0000
1
220
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
180
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
3
950
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
180
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
335
57k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
The Cult of Friendly URLs
andyhume
78
6.1k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Visualization
eitanlees
146
15k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.3k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Transcript
Ruby Trivia 3
What is the value of the global variable $_? Question
1:
The String last read by gets. Answer 1:
How can you list all global variables? Bonus Question:
How can you list all global variables? Bonus Question: Answer:
Use the Kernel#global_variables method.
How many global variables does Ruby define? global_variables.count Bonus Question:
How many global variables does Ruby define? global_variables.count Bonus Question:
Answer: 54.
What does Ruby’s -n switch do? Question 2:
Causes Ruby to assume the following loop around your script,
which makes it iterate over file name arguments like sed -n or awk. while gets ... end Answer 2:
What does Ruby’s -p switch do? Bonus Question:
Acts like the -n switch, but prints the value of
variable $_ at the each end of the loop. For example: ruby -p -e '$_.tr! "a-z", "A-Z"' < file Bonus Question:
What thread-local variable can only store four possible values? Question
3:
What thread-local variable can only store four possible values? Question
3: Hint #1: Those values are 0, 1, 2, and 3.
What thread-local variable can only store four possible values? Question
3: Hint #1: Those values are 0, 1, 2, and 3. Hint #2: The value is 0 by default and can only increase.
$SAFE Answer 3: Trick question because it looks like a
global variable, even though it behaves like a thread-local variable.
$SAFE Answer 3: There used to be $SAFE = 4
but it was removed in Ruby 2.1. Supposedly, it was only ever used by one company in Japan.
How can you check if an object is trusted? Bonus
Question:
How can you check if an object is trusted? Bonus
Question: Answer: Use the Kernel#tainted? method.
What happens if you do this? module Kernel def tainted?
return false end end Question 4:
The tainted? method will always return false, but Ruby will
still track tainted state via an internal FL_TAINT flag. Answer 4:
How can you mark a tainted object as safe? Question
5:
Kernel#untaint a.k.a. Kernel#trust $SAFE = 1 foo = gets.trust eval(foo)
Answer 5:
Thanks for playing! Follow @sferik on Twitter for more Ruby
trivia and practica.