-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuickStart.rb
100 lines (79 loc) · 1.66 KB
/
QuickStart.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
#
# Basics of Ruby!
# - @rahulmfg
# - www.rahulm.me
#
# Print
puts "Welcome, let's code in Ruby!" # this will add new line(\n)
print "So, what is your name? " # this will not add a new line(\n)
# STD Input
your_awesome_name = $stdin.gets.chomp # google about $stdin.gets.chomp vs gets.chomp!
# Printing var w/ string
puts "Yo, #{your_awesome_name}"
# Hash
about = {"name" => your_awesome_name, "id": 1, "key": "qKsa1O"}
# Simple Module
module Emoji
def Emoji.smile()
return "😊"
end
def Emoji.cry()
puts "😭"
end
ABOUT = "My job is to print an Emoji"
end
puts Emoji::ABOUT
smile = Emoji.smile()
puts smile
Emoji.cry()
# IF Statement
if true
puts "Hey, I'm from IF"
end
# IF-ELSE
puts "Do you like Ruby so far?\n1 - Yes\n2 - No"
print '> '
answer = $stdin.gets.chomp.to_i # google about ruby to_i
if answer == 1
puts Emoji.smile()
elsif answer == 2
Emoji.cry()
else
puts "Mmm..."
end
# FOR Loop
numbers = [1, 2, 3, 4]
words = ["Random", "Air", "Hot", "Ufo", "Like"]
for number in (0..10)
puts number
end
numbers.each do |number|
puts number
end
words.each {|word| puts word}
# While Loop
i = 0
while i < words.length
puts words[i]
i += 1
end
# Class
class MoodEmoji
attr_reader :mood # check https://stackoverflow.com/a/5046915/2182940
def initialize(mood)
@mood = mood
end
def emoji()
if @mood == "happy"
puts "You're happy 😊😇"
elsif @mood == "sad"
puts "You're sad ☹️😞"
else
puts "🤔"
end
end
end
happy = MoodEmoji.new("happy")
sad = MoodEmoji.new("sad")
happy.emoji()
sad.emoji()