Skip to content

問題と解答の選択数不一致(Gold, Q26) #22

@t-ueno-ruby

Description

@t-ueno-ruby

Ruby3.1.4で実行して試したところ各選択肢の実行結果が違っていました。
prep-test/gold_answers_ja.md at dccfa77b6d3e409b7d818f4396fecf194f4b5839 · ruby-association/prep-test

解説の修正(もしくは問題の修正?)をお願いしたく存じます。

コード

class Speaker
  @message = "Hello!"

  class << self
    @message = "Howdy!"

    def speak
      @message
    end
  end
end

__(1)__

# [実行結果]
# Hello!

選択肢

A: puts Speaker.speak
B: puts Speaker.singleton_class.speak
C: puts Speaker.instance_variable_get(:@message)
D: puts Speaker.singleton_class.instance_variable_get(:@message)

解答

A: Hello!
B: Howdy!
C: Hello!
D: nil

実際の実行結果

A: Hello!
B: <main>': undefined method speak' for #Class:Speaker (NoMethodError)
C: Hello!
D: Howdy!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions