Last active
December 21, 2015 05:39
-
-
Save babie/6258857 to your computer and use it in GitHub Desktop.
require Ruby 2.0.0 or newer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
module Temperature | |
refine Numeric do | |
def to_fahr | |
self.to_f * 9 / 5 + 32 | |
end | |
def to_cels | |
(self.to_f - 32) * 5 / 9 | |
end | |
end | |
end | |
if __FILE__ == $0 | |
using Temperature | |
modes = { | |
1 => "華氏(F)から摂氏(C)", | |
2 => "摂氏(C)から華氏(F)", | |
} | |
modes.each do |key, val| | |
puts "#{key} #{val}" | |
end | |
print "選択してください: " | |
case gets.to_i | |
when 1 | |
print "温度(F)を入力してください: " | |
f = gets.to_f | |
puts "#{f}F = #{f.to_cels.round(1)}C" | |
when 2 | |
print "温度(C)を入力してください: " | |
c = gets.to_f | |
puts "#{c}C = #{c.to_fahr.round(1)}F" | |
else | |
puts "不正な入力です。" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment