いくつかのルビ関数があり、入力が正しいことと、入力が意味をなすかどうかを確認したいと考えています。それを行うための賢明な方法は何ですか?
これは、私が持っている機能の1つと、確認したいものの例です
# Converts civil time to solar time
# civilT: Time object
# longitude: float
# timezone: fixnum
def to_solarT(civilT,longitude,timezone)
# pseudo code to check that input is correct
assert(civilT.class == Time.new(2013,1,1).class)
assert(longitude.class == 8.0.class)
assert(timezone.class == 1.class)
# More pseudocode to check if the inputs makes sense, in this case
# whether the given longitude and timezone inputs make sense or whether
# the timezone relates to say Fiji and the longitude to Scotland. Done
# using the imaginary 'longitude_in_timezone' function
assert(longitude_in_timezone(longitude,timezone))
end
ここで関連する質問を見つけました: how to put assertions in ruby code。これは行くべき道ですか、それともルビーで関数入力をテストするためのより良い方法はありますか?