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
750
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
2
630
The Value of Being Lazy
sferik
3
850
Ruby Trivia 2
sferik
0
810
Ruby Trivia
sferik
2
1.3k
💀 Symbols
sferik
5
2k
Content Negotiation for REST APIs
sferik
8
1.1k
Writing Fast Ruby
sferik
630
63k
Mutation Testing with Mutant
sferik
5
1.1k
Other Decks in Programming
See All in Programming
20260320登壇資料
pharct
0
110
『Kubernetes ☸️ で実践する Platform Engineering 』を最高速度で読み抜いたる!!👊🏻
hiroki_hasegawa
0
100
AHC061解説
shun_pi
0
410
SourceGeneratorのマーカー属性問題について
htkym
0
210
S3ストレージクラスの「見える」「ある」「使える」は全部違う ─ 体験から見た、仕様の深淵を覗く
ya_ma23
0
900
Kubernetesでセルフホストが簡単なNewSQLを求めて / Seeking a NewSQL Database That's Simple to Self-Host on Kubernetes
nnaka2992
0
180
PHP でエミュレータを自作して Ubuntu を動かそう
m3m0r7
PRO
2
130
野球解説AI Agentを開発してみた - 2026/02/27 LayerX社内LT会資料
shinyorke
PRO
0
360
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
930
Rで始めるML・LLM活用入門
wakamatsu_takumu
0
200
AI Assistants for Your Angular Solutions
manfredsteyer
PRO
0
150
Everything Claude Code OSS詳細 — 5層構造の中身と導入方法
targe
0
150
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
From π to Pie charts
rasagy
0
150
Faster Mobile Websites
deanohume
310
31k
How to Ace a Technical Interview
jacobian
281
24k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.3k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
190
KATA
mclloyd
PRO
35
15k
Thoughts on Productivity
jonyablonski
75
5.1k
Producing Creativity
orderedlist
PRO
348
40k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
84
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.