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?

A

rand()

25
Q

how to take input from the user?

A

gets.chomp

26
Q

what is the method used to compare types?

A

10.eql?(10)

27
Q

how to create an array?

A

a = [1 , 2 , 3]

28
Q

what happens when u use puts to print an array?

A

u print every element in a new line

29
Q

how to access the last element of an array?

A

a.last

30
Q

how to create a range?

A

1..100

31
Q

what is ruby all lower case?

A

it’s a computer program (interpreter) that is used to run and execute ruby files

32
Q

what is irb?

A

interactive ruby console program

irb –simple-prompt

33
Q

types of variables?

A
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
Q

what is intentional about methods?

A

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
Q

how do u construct an object?

A

whether by a literal like the string using ‘ ‘

(quotation) or binding the object to a variable

36
Q

can u call a method without using parenthesis?

A

yes

37
Q

what is a bareword call?

A

puts ‘Hello’

38
Q

what does a class define?

A

the functionality of an object that is created from that class

39
Q

is class or object more important?

A

the object because it can acquire and change behavior after t’s initialized

40
Q

what is the class responsible for?

A

launching the object into existence a process knows as instantiation

41
Q

how to run a syntax check on a ruby program?

A

ruby -cw name.rb

42
Q

what does the -c flag do?

A

check for syntaxt

43
Q

what does -w flag do?

A

check for higher illegalities

44
Q

what is the function used to read from a file?

A

File.read();

45
Q

what is the function used to write to a file?

A

File.new();

46
Q

what is the key to using extensions and libraires?

A

require method , along with it’s near relation load. these methods allow you to load extensions at run time

47
Q

Feature, extension, or library?

A

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
Q

what happens when u call load?

A

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
Q

what is a loading path?

A

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
Q

what is one major difference between load and require?

A

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
Q

what is more abstract require or load?

A

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
Q

what does require allow u to do?

A

require allows you to treat

extensions written in Ruby the same way you treat extensions written in C

53
Q

what do u use more require or load?

A

require

54
Q

what do we use to include files in relative path?

A

require_relative