Ruby Quiz Jan 2022 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What does %x!ls! represents?

A

Same as back tick command output ls

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the output?

>55.to_s(2)

A

“110111” - converts to binary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the output?

  1. nonzero?
  2. nonzero?
A

nil
1

The nonzero?() is an inbuilt method in Ruby returns self if the number is non-zero, else it returns nil.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

def introduce1
__method__
end

def introduce2
__callee__
end

> introduce2
outout?

A

:introduce2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

colors = [“cyan”, “magenta”, “yellow”, “white”];
What is
>Hash[*colors]
will give?

A

{“cyan”=>”magenta”, “yellow”=>”white”}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

> a = [1,2,3,4]
_.to_s
_.class

what is the output?

A

“[1,2,3,4]”
String

_ repeats the last entered code in IRB

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the meaning of this code?

> %I[ Ruby is Cool]

A

[:Ruby, :is, :cool]

Interpolated Array of symbols, separated by whitespace

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
Which one is correct?
%w(ruby is ok)
%i[ruby is ok]
%q{ruby is ok}
%r(ruby)
A

All are correct.these are non-alpha-numeric character delimiters:

 %w(ruby is ok)
 => ["ruby", "is", "ok"] 
3.0.0 :003 > %i[ruby is ok]
 => [:ruby, :is, :ok] 
3.0.0 :004 > %q{ruby is ok}
 => "ruby is ok" 
3.0.0 :005 > %r
 => /ruby is ok/ 
3.0.0 :006 >
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

range = 1..Float::INFINITY

what would be the output?

A

=> 1..Infinity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

range = 1..Float::INFINITY

range.lazy.map { |x| x+x }.first(10)

A

=> [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

array = %w(this is an array)
array * ‘ , ‘

What would be the output

A

=> “this, is, an, array”

join by

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to get range values apart from entries method?

A
>p *(1..5)
1
2
3
4
5
=> [1, 2, 3, 4, 5]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
my_proc = -> argument { puts argument }
Which one is valid?
a)my_proc.call('hello')
b)my_proc.('hello')
c)my_proc['hello']
A

all are valid

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What would be the output?

> [*(‘a’..’e’)]

A

=> [“a”, “b”, “c”, “d”, “e”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which delimiter is used to execute shell commands in ruby?

A

%x[ ] # Interpolated shell command

How well did you know this?
1
Not at all
2
3
4
5
Perfectly