These are generic notes made when i learnt the basics of Object Oriented programming using Ruby.
- Modules can reference public instance methods of the class, for e.g.
1 2 3 4 5 6 7 8 9 10 11 12 13
The above will work ONLY if the class that implements the module Walkable has a public method
name (which is a getter in this case).
It is a good practice to put a comment to that effect where the module is defined.
Only two things evaluate to the boolean
falsein Ruby, they are a null object
Every expression returns something in Ruby. The return value is shown after an hash-rocket sign
=>in an IRB session after executing a line of code.
It's a good idea to just return a string from a method and then using
putson the method call to display the desired string rather than doing a
putsin the method itself.
- A good way to start developing/design an OO application is following the steps below:
- Write the problem statement for the application
- Extract nouns from the problem statement: can be good indicators for required classes
- Extract verbs and associate them with the nouns: can be good indicators of required methods and responsibilities
Note: The above method was put to use here