forked from PilgrimMemoirs/module_exercise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module_exercise.rb
161 lines (145 loc) · 4.96 KB
/
module_exercise.rb
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# ###################################
# ###### NAMESPACE #####
# ###################################
#
# # Provides a container to hold things like methods, classes and constants as a way to group them together logically and to help avoid conflicts with other methods and classes that may have the same name,
# #typically written by someone else (**Ahem, gems**).
#
#
# ###################################
# ###### EXAMPLE MODULE #####
# ###################################
#
# # #
# # module Perimeter
# # class Array
# # def initialize
# # @size = 400
# # end
# # end
# # end
# #
# # our_array = Perimeter::Array.new
# # ruby_array = Array.new
# #
# # p our_array.class
# # p ruby_array.class
# #
# # p our_array.length
#
#
#
#
#
# ###################################
# #### WHY YOU SHOULD LOVE FAKER ###
# ###################################
# #DOCUMENTATION
# #https://github.com/stympy/faker#fakerhacker
# #
# # require "faker"
# #
# # puts Faker::Hacker.say_something_smart
# # puts Faker::Hacker.adjective
# # puts Faker::Hacker.verb
#
#
# #Notice the format of how we're calling the functionality of the Faker gem, How is Faker's code structured?
#
#
#
# ###################################
# ###### TRAVELLER GEM STEP ONE #####
# ###################################
# #DOCUMENTATION:
# #https://github.com/kqdreger/traveller
#
# # #Testing out the traveller gem!
# #
# require 'traveller'
# #
# # trav = Traveller.new("Seattle, Minnesota 98101")
# # print trav
# # puts trav.city
# # puts trav.zip
# #
# # trav.state = "Washington"
# #
# # puts trav.state
#
#
# ###################################
# ###### TRAVELLER GEM STEP TWO #####
# # ###################################
# #
# # #I want to create a new class for travellers, called traveller. What could possibly go wrong?
# # module Jamie
# # class Traveller
# # attr_accessor :name, :email, :city, :state
# # def initialize(details_hash)
# # @name = details_hash[:name]
# # @email = details_hash[:email]
# # @location = details_hash[:location] # this used to use the gem Traveller, but it kept getting busted because of the 2 things named Traveller. So we need to call it outisde the class (line 91)
# # end
# # end
# # end
# #
# # #Tests to use the Traveller Gem (after my class has been created. )
# # traveller2 = Traveller.new("Chicago 60611 IL")
# # puts traveller2.state
# #
# # location = Traveller.new("SEattle wa 98119")
# #
# # user1 = Jamie::Traveller.new({name: "name", email: "email", location: location})
#
#
# #Hmm. It doesn't work. Oh bother.
# #How would we possibly fix this so I don't have to change the name of MY class but still be able to use this gem?
#
#
#
# ###################################
# ######### CONSTANTS ########
# ###################################
#
# #A Ruby constant is like a variable, except that its value is supposed to remain constant for the duration of the program. The Ruby interpreter does not actually enforce the constancy of constants, but it does issue a warning if a program changes the value of a constant
#
# #### NOTES ###
#
# # Constants defined within a class or module may be accessed anywhere within the class or module.
#
# # Outside the class or module, they may be accessed using the scope operator, :: prefixed by an expression that returns the appropriate class or module.
#
# # Constants defined outside any class or module may be accessed as it is or by using the scope operator with no prefix.
# # Constants may not be defined in methods.
#
# # Constants may be added to existing classes and modules from the outside by using the class or module name and the scope operator before the constant name.
module Blackjack
MAX_SCORE = 21
module Player
MAX_PLAYERS = 2
class Player
def initialize
end # end of initialize method
end # end of Player class
end # end of Player module
module Card
MAX_VALUE = 13
class Card
def get_max_value()
return MAX_VALUE
end # end of get_max_value
end # end of class Card
end # end of module Card
end # ened of module Blackjack
MAX_SCORE = 50
MAX_PLAYERS = 4
MAX_VALUE = 21
puts "MAX_SCORE - #{MAX_SCORE}"
puts "Blackjack::MAX_SCORE - #{Blackjack::MAX_SCORE}"
# puts
puts "MAX_Players - #{MAX_PLAYERS}"
puts "Blackjack::Player::MAX_Players - #{Blackjack::Player::MAX_PLAYERS}"
# puts
puts "MAX_VALUE - #{MAX_VALUE}"
puts "Blackjack::Card::get_max_value - #{Blackjack::Card::Card.new().get_max_value()}"