Class: Lita::Handlers::Calculator
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::Calculator
- Defined in:
- lib/lita/handlers/calculator.rb
Instance Method Summary collapse
- #add(response) ⇒ Object
- #divide(response) ⇒ Object
- #multiply(response) ⇒ Object
- #subtract(response) ⇒ Object
Instance Method Details
#add(response) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/lita/handlers/calculator.rb', line 24 def add(response) n = response.matches.first.first n = Integer(n) m = response.matches.first.last m = Integer(m) response.reply "#{n} + #{m} = #{n+m}" end |
#divide(response) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/lita/handlers/calculator.rb', line 47 def divide(response) n = response.matches.first.first n = Integer(n) m = response.matches.first.last m = Integer(m) response.reply "#{n} / #{m} = #{n/m}" end |
#multiply(response) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/lita/handlers/calculator.rb', line 39 def multiply(response) n = response.matches.first.first n = Integer(n) m = response.matches.first.last m = Integer(m) response.reply "#{n} * #{m} = #{n*m}" end |
#subtract(response) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/lita/handlers/calculator.rb', line 32 def subtract(response) n = response.matches.first.first n = Integer(n) m = response.matches.first.last m = Integer(m) response.reply "#{n} - #{m} = #{n-m}" end |