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 2
Erik Berlin
November 05, 2015
Programming
0
440
Ruby Trivia 2
Presented at the Berlin Ruby User Group (RUG::B) on November 5, 2015.
Erik Berlin
November 05, 2015
Tweet
Share
More Decks by Erik Berlin
See All by Erik Berlin
Enumerator::Lazy
sferik
1
220
Ruby Trivia 3
sferik
0
370
The Value of Being Lazy
sferik
3
460
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
heyにおけるCI/CDの現状と課題
fufuhu
1
540
ANR overview at Uber + Leveraging ApplicationExitInfo API
yhartanto
0
320
はてなフォトライフをECSに移行した話 / Hatena Engineer Seminar #20
cohalz
1
810
EFFICIENT CREATION OF AN EMPTY COLLECTION IN .NET
abt
0
150
Independently together: better developer experience & App performance
bcinarli
0
150
Get Ready for Jakarta EE 10
ivargrimstad
0
1.4k
What's new in Android development tools まとめ
mkeeda
0
190
Vite でお手軽 Vue.js の環境構築
azuki
1
170
Dagger + Anvil: Learning to Love Dependency Injection
vrallev
3
230
Cybozu GoogleI/O 2022 LT会 - Input for all screens
jaewgwon
0
190
開発速度を5倍早くするVSCodeの拡張機能を作った
purp1eeeee
2
130
git on intellij
hiroto_kitamura
0
160
Featured
See All Featured
A Tale of Four Properties
chriscoyier
149
21k
StorybookのUI Testing Handbookを読んだ
zakiyama
4
2.2k
Music & Morning Musume
bryan
35
4.2k
A designer walks into a library…
pauljervisheath
196
16k
Navigating Team Friction
lara
175
11k
The Power of CSS Pseudo Elements
geoffreycrofte
46
3.9k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
237
19k
The Art of Programming - Codeland 2020
erikaheidi
32
9.2k
Robots, Beer and Maslow
schacon
152
7.1k
Fashionably flexible responsive web design (full day workshop)
malarkey
396
62k
Infographics Made Easy
chrislema
233
17k
GraphQLとの向き合い方2022年版
quramy
16
8.2k
Transcript
Ruby Trivia 2
What is the return value of Ruby’s method visibility keywords?
private, public, protected Question 1:
self Answer 1: Ruby’s method visibility keywords can be used
as r-values.
Given a button method that takes an argument and a
block, which of these are valid Ruby? button "string" { |n| n } button "string" do |n| n end button ["string"] { |n| n } button ["string"] do |n| n end Question 2:
All except: button("string") { |n| n } Answer 2:
How could this line be fixed? button("string") { |n| n
} Bonus Question:
How could this line be fixed? button("string") { |n| n
} Bonus Question: Answer: Add parentheses around the argument.
What is the result of this line: a Hash with
a String key, a Hash with a Symbol key, or a SyntaxError? {"key": "What happens?"} Question 3:
a Hash with a Symbol key* Answer 3: *In Ruby
2.2 and later. In earlier versions, it raises a SyntaxError.
What is the value of each argument? def foo(*w, a:
7, **t) puts "w: #{w}, a: #{a}, t: #{t}" end foo({a: 1, b: 2, "c" => 3, d: 4}) Question 4:
w: [{"c" => 3}] a: 1 t: {:b => 2,
:d => 4} Answer 4:
What happens if you add a positional argument to the
end? def foo(*w, a: 7, **t) puts "w: #{w}, a: #{a}, t: #{t}" end foo({a: 1, b: 2, "c" => 3, d: 4}, 5) Bonus Question:
What happens if you add a positional argument to the
end? w: [{:a=>1, :b=>2, "c"=>3, :d=>4}, 5] a: 7 t: {} Bonus Question:
When you inspect Object.new, Ruby outputs something like: #<Object: 0x00c1a551f1ab1e>
What are the properties and significance of this hex number? Question 5:
1. It’s the object’s address in memory. 2. It’s always
even. 3. It’s double the object’s object_id. Answer 5:
Answer 5:
Thanks for playing! Follow @sferik on Twitter for more Ruby
trivia and practica.