Files Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

lines = File.readlines(“text.txt”)
line_count = lines.size
text = lines.join
puts “#{line_count} lines”

A

file implements a readlines method that reads an entire file into an array, line by line.

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

total_characters = text.length

puts “#{total_characters} characters”

A

characters including white spaces

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

open source

A

cource code to an application or library is made available publicly for other people to look at and use.

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

local variables

A

x = 10
puts x
can be used only in the same place it is defined.

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

scope

A

where a variable can be used

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

global variables

A
def basic_method
puts $x
end
$x = 10
basic_method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

object variables

A
class Square
def initialize(side_length)
@side_length = side_length
end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

class variables

A
class Square
def initialize
if defined?(@@number_of_squares)
@@number_of_squares += 1
else
@@number_of_squares = 1
end
end
def self.count
@@number_of_squares
end
end

a = Square.new
b = Square.new
puts Square.count

ouput : 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
class Square
def self.test_method
puts "Hello from the Square class!"
end
def test_method
puts "Hello from an instance of class Square!"
end
end
Square.test_method
Square.new.test_method
A
Hello from the Square class!
Hello from an instance of class Square!
How well did you know this?
1
Not at all
2
3
4
5
Perfectly