puts “put s”
#
- starts a comment line or used to disable a line of code
“…”
‘…’
\+ - / * % < ><= >=
PEDMAS
PE(M&D) (A&S)
-plus
- minus
- slash (divide)
- asterisk (multiply)
- percent
(modulus - x divided by y with j remaining) The result of % is the j part , the remainder
{…}
Xxx_yyy
Underscore - puts an imaginary space between words in variable names
ex: carpool_capacity
4 vs 4.0
Integer vs floating point number
= (…)
= equals is used to give data (numbers, strings, etc. ) names
-sets a variable
==
x=100 vs x = 100?
variable
ex. type_of_fish = 10
print vs puts
puts has a linefeed in it
Print does not
{} or %{} ?
Always use #{} to format strings
%{} is used when you want to apply strings multiple times
\n
%q{
-
-
-
}Print a multi line string
“””
“”” again
note: use ‘’’ when you need a multiline string that contains #{} formatting, but you don’t want them to be processed yet or at all. Use “”” For all other multiline strings.
gets.chomp
gets retrieves a line of text input from the user AND includes a trailing linefeed
chomp suppresses the linefeed
gets.chomp.to_i
Get a string from the user
chomp off the \n and convert too an integer
ARGV
ARGV.first. vs ARGV first 2nd 3rd etc.
Argument variable
Note: ARGV gets input from the command line while gets.chomp input comes in via the keyboard while the script is running.
ARGV.first is for only one argument
$stdin
Standard input is stream data
close
read
readline
truncate
write(‘stuff’)
seek(0)
Move the read/write location to the beginning of the file.
Modifiers
w
r
a
w+
echo
cat
That;depends;on;how…
You make several lines of into fewer by using ;
functions
def