Metaprogramming Flashcards

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

What is Metaprogramming?

A

Metaprogramming is writing code that manipulates language constructs at runtime.

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

What is Open Class?

A

Open Class is when you can extend or overwrite an existing class ( String in ruby for example )

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

What are the main disadvantages of metaprogramming?

A
  • Overwriting core methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Monkeypatching?

A

Monkey Patch (MP) is any dynamic modification to a class at runtime.

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

What is Dynamic Dispatch?

A

You can wait literally until the very last moment to decide which method to call, while the code is running. (send method)

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

What is Dynamic Method?

A

This technique of defining a method at runtime is called a Dynamic Method. ( define_method )

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

What is Ghost Method?

A

This is a method which are actually don’t exist. ( methiod missing)

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

Why do we need Proc and Lymbda?

A

Because in Ruby block is not object. And if we want to store block somewhere we need to use a variable.

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

Why do we need class_eval and instance_eval?

A
Class_eval allows to add new method to the class
Intance_eval allows to add new methods to the instance of class.
class Hello
end
Hello.class_eval do 
  def hello
    p 'Hello from class Eval'
  end
end
hello = Hello.new
hello.hello # 'Hello from class Eval'
hello.instance_eval do
  def hello2
    p 'Hello from instance eval'
  end
end
hello.hello2 # 'Hello from instance eval'
Hello.new.hello2 #error
How well did you know this?
1
Not at all
2
3
4
5
Perfectly