Ruby/Methods Classes Modules Namespaces5

From Meshplex

Jump to: navigation, search
Image:Ruby_on_rails_tutorials.jpg
Ruby for complete beginners
Ruby Introduction
What can I use RoR for?
Reasons for choosing RoR over other popular programming languages such as php or asp.net .What makes Ruby so much more special
Where can I find RoR? In what “forms” does it come?
How to install RoR.Solutions for both the novice and professional programmers on Windows,Mac OS X and Linux.Prerequisites.
Ruby programming tutorials for beginners:
Ruby Basics
Ruby Variables, Datatypes, Operators
Ruby Symbols
Ruby Statements
Ruby Converting data to another type: type conversion or typecasting
Ruby Arrays, Hashes, Ranges
Ruby Functions and built in functions
Ruby Control structures
Ruby Regular expressions and blocks
Ruby Loops
Ruby Recursion
Ruby Data Structures
Ruby Methods, Classes, Modules, Namespaces
** Pass Arguments in Ruby
** More Ruby Classes
** Ruby Advanced Classes
** Ruby Inheritance
** Ruby Class Explaination
** Ruby Methods
** Ruby Modules and Namespaces
Ruby Exceptions
Ruby Object Oriented Programming
Ruby Multithreading
Ruby File Handling.Input and Output
Ruby Basic GUI
Ruby and databases.Ruby on Rails and MySQL
Ruby Basic CGI.Using fastCGI
Ruby Basic Networking and web programming
Ruby Basic Graphics
Ajax and Rails.Web 2.0 and what it means
Ruby Testing, Debugging, Automation of tasks
Ruby Apache,Capistrano, Mongrel,lighttpd – reviews and tips
Finding a Ruby on Rails ready web hosting company
BONUS: mini tutorial for a simple RoR application

[edit] Ruby Methods, Classes, Modules, Namespaces page 5

The code on the previous page allows you to take a shortcut in the coding process and use less steps when wanting to quickly use writable attributes.The reason why this is possible is because this code:


def size=(size)
@size = size
end
equals to this:
attr_writer :size

How to create readable and writable attributes

Very easily.You can use both attr_reader and attr_writer OR simply use attr_accessor like this:

class Font
attr_accessor :size
def initialize(size)
@size = size
end
end


[edit] Ruby Class Inheritance

The simplest way of explaining the need for class inheritance is when you need to reuse a class inside another class.What do you do, copy all the code again or just reference the other class ?

class Font
def initialize(size)
@size = size
end
def showsize
return @size
end
end
class Family < Font
def initialize(size, family)
super(size)
@family = family
end
def showfamily
return @family
end
end
font = Family.new(“small”, “Geneva”)
puts “The font belongs to the font family “ + font.showfamily
puts “The font has the size and family,respectively “ + font.showfamily + “,“ + font.showsize

Image:Class3.gif

Previous Next