-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex22.rb
105 lines (75 loc) · 1.85 KB
/
ex22.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
101
102
103
puts
prints a line of text
followed by a new line
" "
double quote
make a string by surrounding something with quotes
,
comma
apparently this separates a string from something else such as a math operation
#
comment
anything after one of these will be ignored by ruby
+
add
/
divide
%
percent
gets the percent of something 10 % 100 is 10
< >
less than, greater than
<= >=
less than or equal to, greater than or equal to
=
equals
assign a variable to something
#{}
embed a variable in a string like this "this is a string and a #{variable}
%s
format string
embed a variable in a string like this "this is a string and a %s" % variable
' '
single quote
make a string by surrounding something with quotes
puts "." * 10 # put something 10 times
print
similar to puts, prints something, but doesn't end with a newline
[ ]
square brackets
used with format strings like % [my_eyes, my_hair]
,
comma
this separates arguments such as [1, 2, 3, 4]
\
escape character
allows you to use a special character as if it's not special, as its normal non special self
<<
multi-line string
allows you to for instance puts a long string
()
parentheses
you can pass arguments into functions within these parentheses like new_function(argument1, argument2)
ARGV
the argument variable
all caps because it's a constant
can't change it once it's assigned
the arguments you provide when you run your ruby script are assigned to this variable ARGV
STDIN
standard input
gets
reads the next line from the IO stream
chomp()
by default removes carriage return characters
removes the given record separator
ARGV.first
the first argument that was passed into the script when the script was run
File.open(filename)
returns the value of the block?
this opens a file and assigns it some special code
txt.read()
read whatever's in txt
$0
variable which is assigned the name of the script
CTRL-C
abort