Ruby

28
1292 reads

March 4, 2013

Protected


The same access rules apply when calling the methods of ancestor and descen-dent objects.

23
1306 reads

March 4, 2013

Overriding Methods


There are times when you may want to redefine a method that already exists in some class.

38
1374 reads

March 4, 2013

Ruby Constructor New


The method responsible for bringing an object into being is called the construc-tor. In Ruby, the constructor method is called new.

25
1309 reads

March 4, 2013

Loop Executes at least Once


Ensuring a Loop Executes At Least Once Usually a while loops executes 0 or more times since the Boolean test is evaluated before the loop executes; if the test returns false at the outset, the code in

26
1256 reads

March 4, 2013

Nested Methods Scope


When you run a method that encloses nested methods, those nested methods will be brought into scope outside that method

37
1283 reads

March 4, 2013

Nested Methods


You can nest methods (have one method nested inside another). This gives you a way of dividing up a long method into reusable chunks.

35
1384 reads

March 4, 2013

Method Names


method names in Ruby almost always begin with a lowercase character like this: def fred However, that is a convention, not an obligation.

29
1272 reads

March 4, 2013

Instant Variables


Just remember that there is only ever one copy of a class variable but there may be many copies of instance variables. If this is still confusing, take a look at the program:

26
1250 reads

March 4, 2013

While Modifiers


When you want to execute several expressions using this syntax, you can put them between the begin and end keywords

27
1364 reads

March 4, 2013

WHAT ARE CLASS METHODS FOR?


But why, one may reasonably ask, would you ever want to create a class method rather than the more usual instance method?