-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathquestions.txt
30 lines (18 loc) · 1.4 KB
/
questions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Please Read:
- Chapter 6 Standard Types
- Review Blocks
- Chapter 7 Regular Expressions
- Chapter 22 The Ruby Language: basic types (symbols), variables and constants
1. What is a symbol?
A Symbol is the most basic Ruby object you can create. It's just a name and an internal ID. Symbols are useful because a given symbol name refers to the same object throughout a Ruby program.
2. What is the difference between a symbol and a string?
Symbols are more efficient than strings. Two strings with the same contents are two different objects, but for any given name there is only one Symbol object. This can save both time and memory.
3. What is a block and how do I call a block?
A block consists of chunks of code. You assign a name to a block.The code in the block is always enclosed within braces ({}).
A block is always invoked from a function with the same name as that of the block. This means that if you have a block with the name test, then you use the function test to invoke this block.
You invoke a block by using the yield statement.
4. How do I pass a block to a method? What is the method signature?
if the last argument of a method is preceded by &, then you can pass a block to this method and this block will be assigned to the last parameter.
In case both * and & are present in the argument list, & should come later.
5. Where would you use regular expressions?
while matching patterns in strings.