Ruby’s Believe It Or Not
Ruby February 20th, 2008Hi Folks, Just mentioning some cool facts and truths about my friendly programming language that is Ruby…
These are like brain teasers which any one can ask you at any point of time.
- -Variables in ruby are not the object instead they are mere refrence to the objects that are being created.
- Methods from the kernel are mixed into the object class,the object class is universaly available and so are the methods from the kernel class.
- Difference between Include and extends?
-Include appends the features of a namespace to the current namespace, where as extend appends the functions of a module to and object.
-With Include, the module’s methods become available to the instance methods,and with extend they become available as a class methods. - Difference between load and require of a file?
- The load tends to read the file and inserts the file at that particular point in the source file so that its definitions become available at tat particular point,where as a require is same as load but it does not the load the file if has already been loaded. - Classes in ruby don have what we call a “name”, instead they are constants referring to the object of type Class since in ruby Class is a class
- self is a pseudovariable which can be used on the instance methods of the class, it generally refrences to the current receiver that is the object on whcih the
instance method is invoked. - Alias provides a means by which we can have synonyms for methods.
ex: alias newname oldname
and here the number of parameters must be the same as the old one.Theres something called as alias_method which behaves similarly to the alias method
expect the fact that the parameters must be comma separated values. - Singleton methods are methods that are defined on per object basis, that is theey have sole impact on the object rather then the class or the superclass.
- Reflection in ruby defines an active enviornment which queries the object that deines themselves,extends themselves or may change dynamically.
- In Ruby,Control structures are not objects.
- This is something cool which I am going to tell you now,for a given object, you can find out a list of methods available on that object by using the “method” method.
For ex:”test”.method will print all the methods avalible for the string class
and this “method” method is defined in the oject class. - The class Module has a method ancestors that returns a list of modules included in the given module
- The ObjectSpace module has access to all live modules.The method “idtoref” converts the object id to an object reference
and there is also another cool method called each_object that iterates over all live objects.









February 23rd, 2008 at 1:15 am
great stuff man