-
Notifications
You must be signed in to change notification settings - Fork 2
/
lesson_seven.rb
75 lines (57 loc) · 1.02 KB
/
lesson_seven.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
$stdout.sync = true
# variable &
name = 'Vasiliy'
result = 42 + 12
number = 42
secret = 'secret'.upcase
# types
# string, number(integer, float), nil, bool (true, false), symbol
# advanced types
# array, hash
unless number == 2 # => bool (true/false)
puts 'never happens'
else
puts 'hello!'
end
# unless number == 2 # if number != 2 # if !(number == 2)
# && - AND => x && y
# || - OR => (x || y)
# ! - NOT => !x
# function
def add_hash(hash)
# add hash to the DB
end
10000.times do |i|
add_hash('wasd')
end
dogs = ['foxy', 'nika', 'max']
dogs.shuffle.each do |dog|
puts "come here #{dog}"
end
cats = [
{ name: 'Ginger', color: 'ginger', age: '4 years' },
{ name: 'Blackie', color: 'black', age: '2 years' }
]
ages = cats.map do |cat|
cat[:age].to_i
end
p ages.each { |a| puts a }
class Cat
attr_reader :age
def initialize(name)
@name = name
@age = 0
end
def meow
puts 'meow!'
end
def happy_bday
puts 'hooray!'
@age += 1
end
end
cat = Cat.new('Marlen')
cat.happy_bday
cat.happy_bday
# ???
puts cat.age