Basics Flashcards
What is Ruby?
Ruby is a high level programmming language
- Ruby is Interperated (no need for a compiler)
- Object oriented (allows users to manipulate data structures)
- Easy to use
What kind of data types are there in Ruby?
String = 'Hello' Fixnum = Number Integer = Number Numeric = class of number like float, fixnum Float = decimal number NilClass = The class of the singleton object nil. Hash = A Hash is a dictionary-like collection of unique keys and their values. Symbol =Symbol objects represent names and some strings inside the Ruby interpreter. Array = A list of objects Range = A Range represents an interval—a set of values with a beginning and an end.
What is a variable?
One of the most basic concepts in computer programming is the variable. You can think of a variable as a word or name that grasps a single value.
my_num = 25
What arithmetic operator are there in ruby?
addition + subtraction - multiplication * division / modulo % exponentiation **
What is the difference between puts and print?
print just prints whatever you give it to the screen
puts (“put string”) prints out what you give it with an empty line
So the difference is that puts has one more line
added.
What is a method in ruby?
They are built in abilities that objects have
methods can show you the length of a string or reverse the string.
What is an interpreter?
An interpreter is a program that takes your code and runs it, it shows the result in your console
How do you use a method?
Methods are used with a .
my_string = ‘i love pizza’ –> my_string.length –> 12
How do write a comment in ruby?
you use #
Everything behind the (on the same line) # will be commented out
How do you do a multiline comment in Ruby?
You use =begin and =end
Everything in between will be commented out, you can use this to explain complicated concepts.
What is a naming convention?
A naming convention is how the community writes code, local variables should be written in lowercase letters and words.
How do you declare or set a variable?
You use the =
my_number = 12
How can you call multiple methods on a variable?
by chaining
name.method1.method2.method3
What is chaining?
Chaining is that you call multiple methods on a variable