Ruby/Methods Classes Modules Namespaces3

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 3


Image:Method5.gif

[edit] Ruby Classes


From what you've learned so far, you've probably come to realize that in Ruby everything is an object.All objects belong to a certain "type", a class in fact. For example, let's take a number, any number, like 534 for example.This belongs to the class called Fixnum.How do you verify this?

Run this command in the irb:

puts 534.class

This is the output:

Image:Class.gif

[edit] How to create a new class in Ruby

class MyClass
end

This is empty for starters.Also, notice how the class name needs to start with a capital letter.

Here's a more advanced example:

class Displaying
 def initialize(msg)
 @message = msg
 end
 
 def showmessage
     return @message
 end 
end
 
display = Displaying.new("this is a test message")
puts display.showmessage

Here is the result:

Image:Class2.gif


Previous Next