-
Notifications
You must be signed in to change notification settings - Fork 0
/
learnRuby.rb
78 lines (56 loc) · 1.6 KB
/
learnRuby.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
# This is a single-lined comment.
=begin
This is a
multi-lined comment
in Ruby.
=end
my_variable = "Hi mom!" # Standard naming convention: start with a lowercase and space words by underscores.
puts my_variable
puts my_variable.upcase
puts my_variable.downcase
puts my_variable.reverse
puts my_variable.length
puts "Puts is a little different from print"
#And now, for something completely different.
print "What is your first name? "
first_name = gets.chomp
#gets is the Ruby method that gets input from the user.
#chomp removes the extra blank line that gets inserts.
first_name.capitalize!
print "What is your last name? "
last_name = gets.chomp
last_name.capitalize!
print "What city are you from? "
city_name = gets.chomp
city_name.capitalize!
print "What state are you from (abbreviate)? "
state_name = gets.chomp
state_name.upcase!
puts "Your name is #{first_name} #{last_name} and you are from #{city_name}, #{state_name}."
=begin
Ruby's boolean operators
and &&
or ||
not !
Comparators/Relational operators
is equal to ==
is not equal to !=
is less than <
is less than or equal to <=
is greater than >
is greater than or equal to >=
=end
my_var = false
puts "An 'unless' statement that is valued true will not execute." unless
my_var
# The following is the Daffy Duck-inator which teachs how to use the .gsub method and replacing variable values.
puts "~~Welcome to the Daffy Duck-inator!~~"
print "Type your string here: "
user_input = gets.chomp
user_input.downcase!
if user_input.include? "s"
user_input.gsub!(/s/, "th")
puts "Translation: #{user_input}"
else
print "WTH man, you messed this up!"
end