Ruby (programming language)
Matsumoto defined it this way in an interview:Ruby is object-oriented: every value is an object, including classes and instances of types that many other languages designate as primitives (such as integers, booleans, and "null"). Variables always hold references to objects. Every function is a method and methods are always called on an object. Methods defined at the top level scope become methods of the Object class. Since this class is an ancestor of every other class, such methods can be called on any object. They are also visible in all scopes, effectively serving as "global" procedures. Ruby supports inheritance with dynamic dispatch, mixins and singleton methods (belonging to, and defined for, a single instance rather than being defined on the class). Though Ruby does not support multiple inheritance, classes can import modules as mixins.
ERuby
The second code snippet changes to the below code:
string = "The value of x is: #{x}"
x = 400
puts string
The above code will not get executed. This is because the 1st line does not know the value of x when it gets executed. Thus, the main reason of using an ERB object is to write templates ahead of time, by "binding" variables and methods which may not exist at the given time. The template gets processed only when "result" is called on the ERB object. In order to get access to instance methods and instance variable of an object, ERB makes use of a "binding" object. Access to variables and methods of an object is given by the private "binding" object which exists in each ruby class. It is easy to get access to methods and variables within the method of a class. But to access variables of a different class, that class will have to expose its binding object via a public method. The example is as shown below:
class ERBExample