Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
11
Task/Enumerations/Ruby/enumerations-1.rb
Normal file
11
Task/Enumerations/Ruby/enumerations-1.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
module Fruits
|
||||
APPLE = 0
|
||||
BANANA = 1
|
||||
CHERRY = 2
|
||||
end
|
||||
|
||||
# It is possible to use a symbol if the value is unrelated.
|
||||
|
||||
FRUITS = [:apple, :banana, :cherry]
|
||||
val = :banana
|
||||
FRUITS.include?(val) #=> true
|
||||
12
Task/Enumerations/Ruby/enumerations-2.rb
Normal file
12
Task/Enumerations/Ruby/enumerations-2.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
module Card
|
||||
# constants
|
||||
SUITS = %i(Clubs Hearts Spades Diamonds)
|
||||
SUIT_VALUE = SUITS.each_with_index.to_h # version 2.1+
|
||||
# SUIT_VALUE = Hash[ SUITS.each_with_index.to_a ] # before it
|
||||
#=> {:Clubs=>0, :Hearts=>1, :Spades=>2, :Diamonds=>3}
|
||||
|
||||
PIPS = %i(2 3 4 5 6 7 8 9 10 Jack Queen King Ace)
|
||||
PIP_VALUE = PIPS.each.with_index(2).to_h # version 2.1+
|
||||
# PIP_VALUE = Hash[ PIPS.each.with_index(2).to_a ] # before it
|
||||
#=> {:"2"=>2, :"3"=>3, :"4"=>4, :"5"=>5, :"6"=>6, :"7"=>7, :"8"=>8, :"9"=>9, :"10"=>10, :Jack=>11, :Queen=>12, :King=>13, :Ace=>14}
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue