-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintro.rb
More file actions
66 lines (55 loc) · 1.25 KB
/
intro.rb
File metadata and controls
66 lines (55 loc) · 1.25 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
# PRINT: Puts - next line, Print - same line
puts "hello world!"
print "heyy"
# VARIABLES
name = "Anshika"
puts "Hello #{name} " + name
# DATA TYPES
## numbers
time = 60
dist = 7.8
## bool
if(0)
puts "0 is truthy"
else
puts "0 is falsey"
end
if(nil)
puts "true"
else
puts "only nil and false are falsey"
end
## strings
greet = "Welcome"
name = "Anshika"
puts "using double quotes: \n" + "#{greet}, #{name}. Let's meet in c:\\books"
puts 'using single quotes: \n' + '#{greet}, #{name}. Let\'s meet'
## hashes (object in js)
name_age = {"a" => 20, "b" => 30, "c" => 14, "d" => 17,};
name_age.each do |k, v|
puts "Name: #{k}, age: #{v}"
end
newHash = Hash.new(1000000)
puts newHash[0]
print name_age
## array
arr = [1, "string", 4.9, true, {"key1" => "value1", "key2" => "value2"}]
arrString = %w{apple banana cherry dragon-fruit}
puts "Array of strings with %w: #{arrString.inspect}"
arr.each do |i|
puts i
end
## symbols: light-weight strings
=begin
when we use string, let's say 'name', ruby creates a new object every time we use it
but when we use symbol, let's say ':name', ruby reuses it
=end
hash_symbol = {
:a => "apple",
:b => "banana",
:c => "citrus",
:d => "dragon fruit",
}
hash_symbol.each do |key, value|
puts "#{key} - #{value}"
end