Idiosyncratic Ruby

Quiz


@JanLelisDecember 2017RUG::B

idiosyncratic-ruby.com

Documenting lesser-known features in Ruby


"Escape Ruby" Edition

Question 1


What is the output of

?????:?????:??

A: "?"

Answer 1

?? ? ?? : ?? ? ?? : ??

"?" ? "?" : "?" ? "?" : "?"

"?" ? "?" : ("?" ? "?" : "?")

"?" ? "?" : "?"

"?"

Question 2


What is the output of

%%%%%%%%%%%

A: ""

Answer 2

%%%%%%%%%%%

%%% % %%% % %%%

"" % "" % ""

"" % ""

""

Bonus Question 2


What is the output of

% % % % % % % %

A: "%"

Bonus Answer 2

% % % % % % % %

"%"%"%"%"%"

"%" % "%" % "%"

"%" % "%"

"%"

Question 3

What is the result?


"RUG::B".gsub(/(.*)::/, '\&\&')
"RUG::RUG::B"

"RUG::B".gsub(/(.*)::/, '\\&\\&')
"RUG::RUG::B"

"RUG::B".gsub(/(.*)::/, '\\\&\\\&')
"\\&\\&B"

"RUG::B".gsub(/(.*)::/, "\&\&")
"&&B"

"RUG::B".gsub(/(.*)::/, "\\&\\&")
"RUG::RUG::B"

"RUG::B".gsub(/(.*)::/, "\\\&\\\&")
"RUG::RUG::B"

Bonus Question 3

What is the result?


"RUG::B".gsub(/(.*)/, '\1')
"RUG::B"

"RUG::B".gsub(/(.*)/, '\\1')
"RUG::B"

"RUG::B".gsub(/(.*)/, '\\\1')
"\\1\\1"

"RUG::B".gsub(/(.*)/, "\1")
"\u0001\u0001"

"RUG::B".gsub(/(.*)/, "\\1")
"RUG::B"

"RUG::B".gsub(/(.*)/, "\\\1")
"\\\u0001\\\u0001"

Question 4


How many ways does Ruby provide to embed a NULL Byte?

Hint: For example, "\x00" embeds a null byte


A: 40

Bonus Question 4

What?

"\0" "\x00" "\x0" "\u0000" "\u{0000}" "\u{000}" "\u{00}" "\u{0}" "\u{00000}" "\u{000000}" "\000" "\00" "\C-\0" "\C-\x00" "\C-\x0" "\C-\000" "\C-\00" "\C-@" "\C-\x40" "\C-\100" "\C-`" "\C-\x60" "\C-\140" "\C- " "\C-\x20" "\C-\40" "\c\0" "\c\x00" "\c\x0" "\c\000" "\c\00" "\c@" "\c\x40" "\c\100" "\c`" "\c\x60" "\c\140" "\c " "\c\x20" "\c\40"

This was Ruby Quiz

@JanLelis