Ruby Flashcards

1
Q

how to comment in ruby?

A

#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

how to print in ruby?

A

puts and has a new line returns nil
p returns the argument
print no new line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what does puts return?

A

nil as in ruby everything returns something

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

how to define a variable?

A

gretting = ‘hello world’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

how to define a function?

A

def greeting(say_something)
puts ‘hello’
end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

can u call a function before u define it?

A

no u must define it first

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is the difference between single quotes and double quotes?

A

with single quotes u can’t do string interpolation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

how to concatenate strings?

A

with +

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how to do string interpolation?

A

with “ #{variable} “

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

how to know the type of the variable?

A

variable.class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is an important rule in ruby?

A

everything is an object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

how to know the built in methods for a variable?

A

variable.methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

how to convert a variable to a string?

A

variable.to_s

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

can u chain methods in ruby?

A

yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

how to know the length of a variable?

A

variable.length

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

how to reverse a string?

A

variable.reverse

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

how to capitalize a variable?

A

variable.capitalize

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

how to check if a variable is empty?

A

variable.empty?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

how to check if a variable in nil?

A

variable.nil?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

how to replace a part of a string?

A

variable.sub

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

what is the difference between sub and gsub?

A

gsub replaces multiple occurances

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

what happens when u assign a variable to another variable?

A

they are both pointing to the same place in memory and if u change one variable the other don’t cuz he is still pointing to that place in memory

23
Q

what is a simple solution for loops?

A

number.times{}

24
Q

how to generate a random number?

25
how to take input from the user?
gets.chomp
26
what is the method used to compare types?
10.eql?(10)
27
how to create an array?
a = [1 , 2 , 3]
28
what happens when u use puts to print an array?
u print every element in a new line
29
how to access the last element of an array?
a.last
30
how to create a range?
1..100
31
what is ruby all lower case?
it's a computer program (interpreter) that is used to run and execute ruby files
32
what is irb?
interactive ruby console program irb --simple-prompt
33
types of variables?
``` 1 - local variables: write them with underscore 2 - instance variables: storing informtation in individual objects and starts with @ 3 - class variables: start with @@ and store information on the class hierarchy 4 - global variables: start with $ 5 - constants: starts with Uppercase FirstName or FIRST_NAME 6 - ```
34
what is intentional about methods?
that it blends with the code it was meant to not know whether it's a variable or a method call and it follows the local variable semantics but end with ? or ! or =
35
how do u construct an object?
whether by a literal like the string using ' ' | (quotation) or binding the object to a variable
36
can u call a method without using parenthesis?
yes
37
what is a bareword call?
puts 'Hello'
38
what does a class define?
the functionality of an object that is created from that class
39
is class or object more important?
the object because it can acquire and change behavior after t's initialized
40
what is the class responsible for?
launching the object into existence a process knows as instantiation
41
how to run a syntax check on a ruby program?
ruby -cw name.rb
42
what does the -c flag do?
check for syntaxt
43
what does -w flag do?
check for higher illegalities
44
what is the function used to read from a file?
File.read();
45
what is the function used to write to a file?
File.new();
46
what is the key to using extensions and libraires?
require method , along with it's near relation load. these methods allow you to load extensions at run time
47
Feature, extension, or library?
we require a feature Library is more concrete and more common. It connotes the actual code as well as the basic fact that a set of programming facilities exists and can be loaded Extension can refer to any loadable add-on library, but it’s often used to mean a library for Ruby that’s been written in the C programming
48
what happens when u call load?
u read the second file and If the file you’re loading is in your current working directory, Ruby will be able to find it by name. If it isn’t, Ruby will look for it in the load path. A call to load always loads the file you ask for, whether you’ve loaded it already or not. If a file changes between loadings, anything in the new version of the file that rewrites or overrides anything in the original version takes priority.
49
what is a loading path?
is a list of directories in which it searches for files you ask it to load. You can see the names of these directories by examining the contents of the special global variable $: (dollar-colon).
50
what is one major difference between load and require?
require, if called more than once with the same arguments, doesn’t reload files it’s already loaded. Ruby keeps track of which files you’ve required and doesn’t duplicate the effort
51
what is more abstract require or load?
require as u don't require a file u require a feature and u don't have to specify the extension on the filename
52
what does require allow u to do?
require allows you to treat | extensions written in Ruby the same way you treat extensions written in C
53
what do u use more require or load?
require
54
what do we use to include files in relative path?
require_relative