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
560
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
390
The Value of Being Lazy
sferik
3
590
Ruby Trivia 2
sferik
0
610
Ruby Trivia
sferik
2
1.1k
💀 Symbols
sferik
5
1.6k
Content Negotiation for REST APIs
sferik
8
820
Writing Fast Ruby
sferik
622
60k
Mutation Testing with Mutant
sferik
5
990
Other Decks in Programming
See All in Programming
パフォーマンスを求めてDBに機能を寄せる戦略
aoyagikouhei
0
110
AmperとFleetを使ったAndroidアプリ
yoppie
0
270
PostmanでAPIの動作確認が楽になった話
h455h1
0
190
Komplexe Oberflächen mit SVG und der Web Animation API
joergneumann
0
680
雑に思考を整理する技術と効能
konifar
64
31k
Git Lint
bkuhlmann
4
760
Native Federation: The Future of Micro Frontends in Angular
manfredsteyer
PRO
0
130
Deep Dive into React Stream/Serialize
mugi_uno
3
740
Site Reliability Engineering for GMO
pyama86
9
1.1k
Go製Webアプリケーションのエラーとの向き合い方大全、あるいはやっぱりスタックトレース欲しいやん / Kyoto.go #50
utgwkk
6
1.8k
JavaScript Closure
asoluka
0
610
サイコロで理解する統計的仮説検定の考え方
tatamiya
4
1.1k
Featured
See All Featured
KATA
mclloyd
16
12k
Intergalactic Javascript Robots from Outer Space
tanoku
266
26k
Agile that works and the tools we love
rasmusluckow
325
20k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
14
8.4k
Build The Right Thing And Hit Your Dates
maggiecrowley
25
2k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
Building Your Own Lightsaber
phodgson
100
5.7k
Navigating Team Friction
lara
179
13k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
20
1.8k
10 Git Anti Patterns You Should be Aware of
lemiorhan
649
58k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
242
1.2M
Side Projects
sachag
451
41k
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.