-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject_orientation.rb
More file actions
79 lines (63 loc) · 1.31 KB
/
object_orientation.rb
File metadata and controls
79 lines (63 loc) · 1.31 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
# Métodos
def sum_numbers(num1, num2)
return num1 + num2
end
puts sum_numbers(10, 20)
# Classes
class Calculator
attr_accessor :phrase
def initialize(num1, num2)
@num1 = num1
@num2 = num2
end
def sum
return @num1+@num2
end
def minus
return @num1-@num2
end
def multiplication
return @num1*@num2
end
def division
return @num1/@num2
end
def exponentization
return @num1**@num2
end
def square_root
return Math.sqrt(@num1)
end
end
calc = Calculator.new(50, 2)
puts calc.division
calc.phrase = "Hello, World"
puts calc.phrase
class Restaurante
attr_accessor :nota
def initialize(name)
puts "O Restaurante chamará: #{name}"
@name = name
end
def send(options = {})
endereco = options.fetch(:adress, "adress")
puts "Enviaremos para %s" %(endereco)
end
def feedback(msg="Obrigado pela avaliação")
if nota.to_i <= 5.9
resposta = "Tentaremos melhorar sempre que possível!"
elsif nota.to_i >= 6
resposta = "Vamos melhorar nosso atendimento. Até mais."
elsif nota.to_i > 8
resposta = "Volte sempre!"
elsif nota.to_i == " "
resposta = "Houve um problema com nosso Sistema."
end
puts "#{msg} nota #{nota}. #{resposta}"
end
end
abc = Restaurante.new("Ruby Restaurant")
puts "Digite a nota: "
abc.nota = gets.chomp
abc.feedback
abc.send(adress: "Example 123")