Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Ruby Trivia 3
Erik Berlin
December 03, 2015
Programming
0
370
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
220
The Value of Being Lazy
sferik
3
460
Ruby Trivia 2
sferik
0
440
Ruby Trivia
sferik
2
960
💀 Symbols
sferik
5
1.3k
Content Negotiation for REST APIs
sferik
8
650
Writing Fast Ruby
sferik
612
57k
Mutation Testing with Mutant
sferik
5
890
Other Decks in Programming
See All in Programming
GDG Seoul IO Extended 2022 - Android Compose
taehwandev
0
270
Voiceflowではじめる音声アプリ・チャットボット開発〜2022年版〜 / Introduction to Developing Voice Apps & Chatbots with Voiceflow
kun432
0
170
Beyond Micro Frontends: Frontend Moduliths for the Enterprise @enterjs2022
manfredsteyer
PRO
0
100
はてなフォトライフをECSに移行した話 / Hatena Engineer Seminar #20
cohalz
1
810
言語処理ライブラリ開発における失敗談 / NLPHacks
taishii
1
420
Reactアプリケーションのテスト戦略
0906koki
10
4.6k
Cybozu GoogleI/O 2022 LT会 - Input for all screens
jaewgwon
0
190
EFFICIENT CREATION OF AN EMPTY COLLECTION IN .NET
abt
0
150
engineer
spacemarket
0
460
Terraform Plan/Apply結果の自動通知
ymmy02
0
270
Amazon Aurora の v1 が EOL になるので 10 クラスタアップグレードして出てきたノウハウ
dekokun
0
840
git on intellij
hiroto_kitamura
0
160
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
212
20k
We Have a Design System, Now What?
morganepeng
35
2.9k
Documentation Writing (for coders)
carmenhchung
48
2.5k
Building a Scalable Design System with Sketch
lauravandoore
447
30k
GitHub's CSS Performance
jonrohan
1020
420k
What's in a price? How to price your products and services
michaelherold
229
9.4k
Three Pipe Problems
jasonvnalue
89
8.7k
How To Stay Up To Date on Web Technology
chriscoyier
780
250k
The Art of Programming - Codeland 2020
erikaheidi
32
9.2k
Designing for humans not robots
tammielis
241
23k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
498
130k
Keith and Marios Guide to Fast Websites
keithpitt
404
21k
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.