Rubyがミニツク

あなたのRubyの技術に関するより詳しい知識と理解を増やします。

Certified Ruby Programmer Silver Preparation Course

このコースについて

This course contains a set of drills that you can study to prepare yourself for the Certified Ruby Programmer Silver Examination.

コンテンツ一覧

ヒント レッスンの名前をクリックすると、その内容を表示します。

コース一覧に戻る ホームへ戻る

Certified Ruby Programmer Silver Preparation Course - Part 7

コンテンツ概要

Prepare Yourself for the Ruby Association Certified Ruby Programmer (Silver) Examination with the practice questions in this series of drills. The series cover the test curriculum as set out by the Ruby Association. This part deals with Ruby's built-in Time class. Note, the questions in this drill assume Ruby version 1.8.7 unless otherwise stated.

このドリルは6問の問題があります。


はじめる

問題

Choose the option that corresponds to the line in the code which causes “true” to be printed to the standard output.

t = Time.now
puts t #=> Tue Jun 21 17:44:08 +0900 2011
puts t.wday.to_s == t.strftime("%A")       # (a)
puts t.year.to_s == t.strftime("%y").class # (b)
puts t.zone == t.strftime("%Z")            # (c)
puts t.hour.to_s == t.strftime("%I")       # (d)

選択肢を選ぶ

(a) puts t.year.to_s == t.strftime("%y").class

(b) puts t.zone == t.strftime("%Z")

(d) puts t.hour.to_s == t.strftime("%I")

(c) puts t.hour.to_s == t.strftime("%I")


次の問題へ進む

問題

Which of the following expressions will return a Time object representing the time at exactly 24 hours ago?

選択肢を選ぶ

(a)

Time.now - 1

(c)

Time.yesterday

(d)

Time.now - 24

(b)

Time.now - 86400


次の問題へ進む

問題

Choose the option containing the correct replacements for (A) and (B) in the following program, given that the program must produce the specified output (as specified with #=>).

  t = Time.now()
  puts t.(A)  #=>Tue Jun 21 05:36:03 UTC 2011
  puts t.utc? #=>false
  puts t.(B)  #=>Tue Jun 21 05:36:03 UTC 2011
  puts t.utc? #=>true

選択肢を選ぶ

(d) getutc, utc

(c) getlocal, getutc

(b) localtime, getlocal

(a) getutc, getutc


次の問題へ進む

問題

What is the output of the following code?

t1 = Time.at(0.5)
t2 = Time.at(0.9)
print t1.to_s == t2.to_s
print " "
print "%.1f" % t1.to_f == "%.1f" % t2.to_f

選択肢を選ぶ

(d) false true

(c) true false

(b) true true

(a) false false


次の問題へ進む

問題

Choose the correct replacement for (A) in the following program, given that the program must produce the specified output (as specified with #=>).

t = Time.at(0)
fs = "The Unix epoch starts in year %Y"
p (A)
#=> "The Unix epoch starts in year 1970"

選択肢を選ぶ

(d)

t.to_s(fs)

(b)

t.strftime(fs)

(a)

t.strformat(fs)

(c)

fs % t


次の問題へ進む

問題

Which of the following expressions return a new Time object, initialized to represent 00:00:01 UTC on the 23rd of June, 2012?

選択肢を選ぶ

(b) Time.at(2012, 6, 23, 00, 00, 01)

(a) Time.new(2012, 6, 23, 00, 00, 01)

(c) Time.utc(2012, 6, 23) + 1

(d) Time.local(2010, 6, 23, 00, 00, 01)


コース一覧に戻る ホームへ戻る