LoginSignup
7
0

Ruby Gold 3.1のテストに2回落ちました

Posted at

Ruby Gold 3.1の資格を受験して、2回落ちて3回目で合格できました。
rubyのバージョンが3に上がってからの、受験記録の記事はあまり数が多くないと感じたため、受験した中で、回答に迷った問題をまとめます。
点数の履歴は、70点、68点、80点でした。

なお、バージョン3の参考記事としては、下記が非常に参考になりました。
https://qiita.com/heysan/items/82bdfb7af4325f05e0e5

1問目

a = _(1)_ # ここを問う問題
    Ruby Gold
    version 3
  EOS
puts a

(実行結果)
Ruby Gold
version 3

選択肢として、以下のようなものがでました。

  1. <<~EOS
  2. <<EOS.gsub(/ /, "")<<EOS.gsub(/ /, "")
  3. <<-EOS.gsub(/ /, "")
  4. <<-EOS.gsub(/^*/, "")
  5. <<-EOS

2問目

require 'forwardable'

class List
  extend Forwardable

  def initialize
    @contents = []
  end

  def_delegator :@contents, :push
end
begin
  list = List.new
  list.push("b")
  p list[0]
rescue
  puts "er"
end

[実行結果]
"er"# ここを問う問題

エラーが出るのか、出ないのかで迷いました。
extend Forwardableじゃなくて、includeだったっけ?
def_delegatorの定義が足りないか?など。

3問目

def add(x:, y:, **params)
  p params
end

add(x: 3.75, y: 3, round: true)

[実行結果]
{:round=>true} # ここを問う問題

選択肢として、以下の用な感じのものがでました。

  1. {:round=>true}
  2. {round=>true}

4問目

# コード1
[1,2,3].each do |n|
  num = n
end
p num

# コード2
num = 0
[1,2,3].each do |n|
  num = n
end
p num

コード1とコード2の実行結果を問う問題が出ました。

5問目

class A
  def foo
    "foo"
  end
  private
  def bar
    "bar"
  end
end
obj=A.new
p # ここを問う問題

エラーが出る選択肢を選ぶ
1. obj.send(:bar)
2. obj.public_send(:foo)
3. obj.private_send(:bar)
4. obj.__send__(:bar)

6問目

class A
  @a=1
end
p A.instance_variables

結果の選択肢として以下のような感じで出ました。

  1. [:@a]
  2. [:a]
  3. [@a]
  4. [a]

7問目

array=[1,2,3]
p array.lazy.take(3).force
p array.first(3)
p array.last(3)

詳しく覚えてないのですが、このような雰囲気の問題がでました。

7
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
0