Ruby

348
4196 reads

February 28, 2013

Handling Missing Method1


When Ruby tries to execute an undefined method (or, in OOP terms, when an object is sent a message which it cannot handle), the error causes the program to exit.

346
2611 reads

February 28, 2013

Special Eval:- Module_eval


The module_eval and class_eval methods operate on modules and classes rather than on objects.

210
3282 reads

February 28, 2013

Special Eval :- Instance_eval


There are some variations on the eval theme in the form of the methods named instance_eval, module_eval and class_eval.

26
1404 reads

February 28, 2013

Eval3


The eval method can evaluate strings spanning many lines, making it possible to execute an entire program embedded in a string

24
1332 reads

February 28, 2013

Eval String


There are times, however, when the results may not be what you are expecting. Look at the following, for instance:

exp = gets().chomp()
puts( eval( exp ))
puts( "#{exp}" )

28
1764 reads

February 28, 2013

Eval Magic


The eval method provides a simple way of evaluation a Ruby expression in a string.

40
1360 reads

February 28, 2013

Dynamic


Using Send to Create a New Method

37
1373 reads

February 28, 2013

Creating Classes at Runtime


So far we have modified classes and created new objects from existing classes. But how would you go about creating a completely new class at runtime?

32
1213 reads

February 28, 2013

Adding Variables and Methods


adding and retrieving class variables from outside a class (using class_eval); it turns out that there are also methods de-signed to do this from inside a class.

35
1457 reads

February 28, 2013

Freezing Objects


With all these ways of modifying objects at your disposal, you may be concerned that objects are at risk of being modified unintentionally.