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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Erik Berlin
December 03, 2015
Programming
770
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
650
The Value of Being Lazy
sferik
3
870
Ruby Trivia 2
sferik
0
830
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
ReactとSvelteのその先、Ripple-TS / Beyond React and Svelte: Ripple-TS
ssssota
3
840
Claspは野良GASの夢をみるか
takter00
0
110
AI駆動開発勉強会 広島支部 第一回勉強会 AI駆動開発概要とワークショップ
hayatoshimiu
0
390
AI駆動開発で崩れていくコードベースを立て直す
kyoko_nr_nr
1
380
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
330
密結合なバックエンドから TypeScript のコードを生成する
kemuridama
1
350
AI時代だからこそ「Bloc」を採用する価値があるのかもしれない
takuroabe
0
240
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
150
iOS26時代の新規アプリ開発
yuukiw00w
0
200
今さら聞けないCancellationToken
htkym
0
190
RailsTokyo 2026#4: AI様があれば、 Hotwireの弱点は消えるか?
naofumi
5
980
Why Laravel apps break—Mastering the fundamentals to keep them maintainable
kentaroutakeda
1
270
Featured
See All Featured
Ruling the World: When Life Gets Gamed
codingconduct
0
240
Prompt Engineering for Job Search
mfonobong
0
320
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2k
Producing Creativity
orderedlist
PRO
348
40k
GraphQLとの向き合い方2022年版
quramy
50
15k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
180
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
Believing is Seeing
oripsolob
1
130
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
1.5k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
170
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.