-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath.rb
More file actions
executable file
·130 lines (113 loc) · 2.19 KB
/
math.rb
File metadata and controls
executable file
·130 lines (113 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#! /home/sugryo/.rbenv/versions/2.1.1/bin/ruby
# -*- coding: utf-8 -*-
option = ARGV[0]
module MathOptions
def version
puts "math 0.0.2 (2014-04-22)"
end
def license
puts "math is the terms of a BSD 3-Clause License."
end
def copyright
puts "math - Copyright (c) 2014 Ryo Sugimoto"
end
def help
puts "usage: math.rb [-v] [-c] [-h] [--version] [--license] [--copyright] [--help]"
puts "-v --version see the math version"
puts " --license see the math license"
puts "-c --copyright see the math copyright"
puts "-h --help see the math help"
end
end
def ten?(num)
if num == 10
true
else
false
end
end
def zero_division_error
puts "答えは、0です。"
end
def error
puts "エラーが発生しました。"
end
class Calculations #計算
def initialize(car_numbers)
begin
@car_numbers = car_numbers
rescue
error
end
end
def select(figures)
begin
if ten?(figures)
puts "10になりました!"
else
puts "10になりませんでした。戻り値は#{figures}です。"
end
rescue
error
end
end
private :select
def addition #足し算
begin
figures = 0
@car_numbers.each {|i| figures += i}
select(figures)
rescue
error
end
end
def subtraction #引き算
begin
figures = 0
@car_numbers.each {|i| figures -= i}
select(figures)
rescue
error
end
end
def multiplication #掛け算
begin
figures = 1
@car_numbers.each {|i| figures *= i}
select(figures)
rescue
error
end
end
def division #割り算
begin
figures = 1
@car_numbers.each {|i| figures /= i}
select(figures)
rescue ZeroDivisionError
zero_division_error
rescue
error
end
end
end
def option(option)
include MathOptions
unless option == nil
case option
when "-v", "--version"
version
when "-c","--copyright"
copyright
when "--license"
license
when "-h","--help"
help
else
error = Errors.new
error.error
help
end
end
end
option(option)