forked from jsfowles/ruby_classes_modules_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruby_classes_modules_examples.rb
More file actions
85 lines (59 loc) · 1.74 KB
/
Copy pathruby_classes_modules_examples.rb
File metadata and controls
85 lines (59 loc) · 1.74 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
require 'pry'
# require 'babbler'
# puts 'YAY Friday!'
# def keep_coding
# puts 'Pop question: Are you going to keep coding over the weekend? (yes / no)'
# input = gets.strip.downcase
# # if input == 'yes' ? (puts 'Good answer'): (puts 'You serious, bro? Do you even code?') keep_coding
# if input == 'yes'
# puts 'Good answer!'
# else
# puts Babbler.babble
# # puts 'You serious, bro? Do you even code?'
# keep_coding
# end
# end
# keep_coding
class Person
# It has to match the instance variable
# attr_accessor - read & write
# attr_reader - ready only
# attr_writer - write only
attr_accessor :first_name, :last_name, :age, :gender
# Every time you call 'New' on a class, it calls the initialize
# def initialize (first_name, last_name, age, gender)
# @first_name = first_name
# @last_name = last_name
# @age = age
# @gender = gender
# end
def initialize
puts 'What is the first name?'
@first_name = gets.strip
puts 'What is the last name?'
@last_name = gets.strip
puts 'What is the age?'
@age = gets.strip.to_i
puts 'What is the gender?'
@gender = gets.strip
end
end
# This is creating an instance of this person
# ('Lindsey', 'Font', 26, 'Female')
puts 'Welcome Player 1! Please enter your information:'
player_1 = Person.new
puts 'Is this information correct?'
puts "First name: #{player_1.first_name}\nLast name: #{player_1.last_name}\nAge: #{player_1.age}\nGender: #{player_1.gender}"
validate = gets.strip
if validate == 'yes'
puts 'Awesome.'
else
player_1 = Person.new
end
#('Brandon', 'Font', 32, 'Male')
puts 'Welcome Player 2! Please enter your information:'
player_2 = Person.new
puts player_2.first_name
puts player_2.last_name
puts player_2.age
puts player_2.gender