Module: TfPoint::Calculate

Included in:
TfPointClass
Defined in:
lib/24point/calculate.rb

Instance Method Summary collapse

Instance Method Details

#devision_operation(expa, expb, numa, numb) ⇒ Object

/



26
27
28
29
30
# File 'lib/24point/calculate.rb', line 26

def devision_operation(expa, expb, numa, numb)
  return "", 0 if !numa.is_a?(Fixnum) || !numb.is_a?(Fixnum)
  exp = expa + '/' + expb
  return exp, (numa / numb)
end

#multi_operation(expa, expb, numa, numb) ⇒ Object

*



19
20
21
22
23
# File 'lib/24point/calculate.rb', line 19

def multi_operation(expa, expb, numa, numb)
  return "", 0 if !numa.is_a?(Fixnum) || !numb.is_a?(Fixnum)
	exp = (expa > expb) ? expa + '*' + expb : expb + '*' + expa
  return exp, (numa * numb)
end

#plus_operation(expa, expb, n, numa, numb) ⇒ Object

+ 排序,大的在前,小的在后,如果是最后一次(n=2),不加括号



4
5
6
7
8
9
# File 'lib/24point/calculate.rb', line 4

def plus_operation(expa, expb, n, numa, numb)
  return "", 0 if !numa.is_a?(Fixnum) || !numb.is_a?(Fixnum)
	expa, expb = expb, expa if expa.is_num? && expb.is_num? && expa < expb
	exp = (n == 2) ? expa + '+' + expb : '(' + expa + '+' + expb + ')'
  return exp, (numa + numb)
end

#sub_operation(expa, expb, n, numa, numb) ⇒ Object

-



12
13
14
15
16
# File 'lib/24point/calculate.rb', line 12

def sub_operation(expa, expb, n, numa, numb)
  return "", 0 if !numa.is_a?(Fixnum) || !numb.is_a?(Fixnum)
	exp = (n == 2) ? expa + '-' + expb : '(' + expa + '-' + expb + ')'
  return exp, (numa - numb)
end