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
790
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Ruby Trivia 3
Presented at the Berlin Ruby User Group (RUG::B) on November 5, 2015.
Erik Berlin
December 03, 2015
More Decks by Erik Berlin
See All by Erik Berlin
Enumerator::Lazy
sferik
2
720
The Value of Being Lazy
sferik
3
880
Ruby Trivia 2
sferik
0
840
Ruby Trivia
sferik
2
1.4k
💀 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.2k
Other Decks in Programming
See All in Programming
FDEが実現するAI駆動経営の現在地
gonta
2
240
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
280
Foundation Models frameworkで画像分析
ryodeveloper
1
320
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
250
20260722_microCMSで考える、AI時代のコンテンツ運用設計
yosh1
0
190
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
570
信頼性について考えてみる(SRE NEXT 2026 miniLT)
hayama17
0
230
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.7k
メールのエイリアス機能を履き違えない
isshinfunada
0
200
自動化したのに回らないテスト運用の壁ーAI時代の品質責任と生産性
mfunaki
0
120
GDG Korea Android: 2026 I/O Extended ~ What's new in Android development tools
pluu
0
200
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
200
Featured
See All Featured
A Tale of Four Properties
chriscoyier
163
24k
Into the Great Unknown - MozCon
thekraken
41
2.6k
30 Presentation Tips
portentint
PRO
1
360
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
Mind Mapping
helmedeiros
PRO
1
290
Amusing Abliteration
ianozsvald
1
240
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
440
Paper Plane (Part 1)
katiecoart
PRO
1
10k
Music & Morning Musume
bryan
47
7.3k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
200
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
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.