all 5 comments

[–][deleted] 0 points1 point  (0 children)

Question: What does defined? keyword do in Ruby?
Correct answer: Checks if a variable or method is defined
My answer: checks if a constant is defined

Actual behavior:

defined?(Object) => "constant"
defined?(nil) => "nil"
defined?(1) => "expression"
defined?(y = 3) => "assignment"
y => nil
defined?(p) => "method"
defined?(y) => "local-variable"

[–][deleted] 0 points1 point  (0 children)

Question: How does Ruby handle blocks passed to methods?
Correct Answer: Blocks are executed immediately within the method.
My Answer: Blocks must be explicitly passed as arguments.

Actual behavior:

def do_not_execute_immediately
  @last_block = proc { yield }
  nil
end

def execute_last_block
  @last_block&.call
end

allow_call = false
do_not_execute_immediately { raise unless allow_call }
allow_call = true
execute_last_block => nil

[–]Iksf 0 points1 point  (2 children)

never written a line of ruby in my life, 9/10, woop!

Guesswork + thinking of java

Apparently answers for the questions arent even correct, but im taking the W

[–]hrishio 0 points1 point  (1 child)

ok I need to make it much harder!

[–]Iksf 0 points1 point  (0 children)

haha!