Files Flashcards

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

include

A

allows you to include code defined in the module and insert it into a class ex. module Log def class_type “This class is of type: #{self.class}” end end class TestClass include Log # … end tc = TestClass.new.class_type

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

load

A

similar to require load is there if you want a library to be loaded each time load is called. ex. load ‘test_library.rb’

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

require

A

The require method allows you to load a library and prevents it from being loaded more than once. The require method will return ‘false’ if you try to load the same library after the first time. The require method only needs to be used if library you are loading is defined in a separate file ex. require ‘test_library’

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

extend

A

When using the extend method instead of include, you are adding the module’s methods as class methods instead of as instance methods. ex. module Log def class_type “This class is of type: #{self.class}” end end class TestClass extend Log # … end tc = TestClass.class_type prints This class is of type: TestClass

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

include

A

allows you to include code defined in the module and insert it into a class ex. module Log def class_type “This class is of type: #{self.class}” end end class TestClass include Log # … end tc = TestClass.new.class_type

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

File.open( )

A

opens specified file

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

.read

A

reads file as a string

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

.truncate

A

deletes contents of file ex. filename.truncate

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

.close( )

A

closes the file ex. filename.close()

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

.write(stuff)

A

writes content to file ex. line1= “Hello World!” file.write(line1)

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