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
760
0
Share
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
640
The Value of Being Lazy
sferik
3
860
Ruby Trivia 2
sferik
0
820
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
Explore CoroutineScope
tomoeng11
0
130
アクセシビリティ試験の"その後"を仕組み化する
yuuumiravy
1
180
From Formal Specification to Property Based Test
ohbarye
0
610
AIエージェントで業務改善してみた
taku271
0
550
20年以上続くプロダクトでも使い続けられる静的解析ツールを求めて
matsuo_atsushi
0
110
AIベース静的検査器の偽陽性率を抑える工夫3選
orgachem
PRO
4
380
「話せることがない」を乗り越える 〜日常業務から登壇テーマをつくる思考法〜
shoheimitani
4
940
ついに来た!本格的なマルチクラウド時代の Google Cloud
maroon1st
0
330
Surviving Black Friday: 329 billion requests with Falcon!
ioquatix
0
2.4k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyKaigi 2026, Hakodate, Japan
marcoroth
0
550
クラウドネイティブなエンジニアに向ける Raycastの魅力と実際の活用事例
nealle
2
230
🦞OpenClaw works with AWS
licux
1
310
Featured
See All Featured
Fireside Chat
paigeccino
42
3.9k
Being A Developer After 40
akosma
91
590k
Statistics for Hackers
jakevdp
799
230k
Code Reviewing Like a Champion
maltzj
528
40k
Raft: Consensus for Rubyists
vanstee
141
7.4k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
180
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
110
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
130
Utilizing Notion as your number one productivity tool
mfonobong
4
300
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
110
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.