Class: RubyArithmetic

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_arithmetic.rb

Class Method Summary collapse

Class Method Details

.add(n1, n2) ⇒ Object



2
3
4
5
6
7
# File 'lib/ruby_arithmetic.rb', line 2

def self.add(n1, n2)
    unless(n1.is_a?(Integer) && n2.is_a?(Integer))
        raise "Only integers are allowed"
    end
    return (n1 + n2)
end

.diff(n1, n2) ⇒ Object



16
17
18
19
20
21
# File 'lib/ruby_arithmetic.rb', line 16

def self.diff(n1, n2)
    unless(n1.is_a?(Integer) && n2.is_a?(Integer))
        raise "Only integers are allowed"
    end
    return (n1 - n2).abs
end

.div(n1, n2) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/ruby_arithmetic.rb', line 30

def self.div(n1, n2)
    unless(n1.is_a?(Integer) && n2.is_a?(Integer))
        raise "Only integers are allowed"
    end

    if n2 == 0
        raise "divide by zero error"
    end
    return (n1 / n2)
end

.mul(n1, n2) ⇒ Object



23
24
25
26
27
28
# File 'lib/ruby_arithmetic.rb', line 23

def self.mul(n1, n2)
    unless(n1.is_a?(Integer) && n2.is_a?(Integer))
        raise "Only integers are allowed"
    end
    return (n1 * n2)
end

.rem(n1, n2) ⇒ Object



41
42
43
44
45
46
# File 'lib/ruby_arithmetic.rb', line 41

def self.rem(n1, n2)
    unless(n1.is_a?(Integer) && n2.is_a?(Integer))
        raise "Only integers are allowed"
    end
    return (n1 % n2)
end

.sub(n1, n2) ⇒ Object



9
10
11
12
13
14
# File 'lib/ruby_arithmetic.rb', line 9

def self.sub(n1, n2)
    unless(n1.is_a?(Integer) && n2.is_a?(Integer))
        raise "Only integers are allowed"
    end
    return (n1 - n2)
end