Markers are used as a standard for comparison.
module CreditCardTypesMarkers are initialized to a value; however, that value is unimportant as long as it is unique. Markers are generally used in an application within conditional statements.
Visa = 0
Mastercard = 1
case card.typeNote: you can also use symbols as markers, but I prefer constants. This preference is based on the fact that if I mistype CreditCardTypes::Vissa it will fail fast; however, if I mistype :credit_card_type_vissa, I will get a possibly hard to find bug.
when CreditCardTypes::Visa then VisaLuhnValidator
when CreditCardTypes::Mastercard then MastercardLuhnValidator
Constant values are global values that should never change during the life of your application.
module MathValuesConstant values can be used throughout applications to ensure that the same value is consistently used.
PI = 3.14
circumference = circle.diameter * MathValues::PIBased on these usages, I'm a bit concerned about some behavior I recently found.
irb(main):019:0> module MathVariablesWarning? This means anyone can redefine my constants at any time? Did I do something wrong? Does anyone else think this is dangerous?
irb(main):020:1> PI = 3.14
irb(main):022:0> module MathVariables
irb(main):023:1> PI = 3.14159265
(irb):23: warning: already initialized constant PI