Ruby (1): The simplest programming language yet

If you have some experience on programming especially based on linux kind operating systems (Ubuntu, Mac OS X, so on.), you will find Ruby easy to get familiar with and very simple to use. This article is just for those who have some programming knowledge or experience such as Java, C#, VB.NET, C, C++ or even Objective-C, assuming that you are somewhat familiar with the concept of OOP and basic idea of programming language.
Ruby is quite not the same as those legendary language like C or java. It is very interactive and simple. If you are using Mac OS X, you already have Ruby development environment. Most of linux OS also include any necessary development tools. – You can find further information on some other many websites that can be found by googling. (i.e. http://www.ruby-lang.org)
I will let you look up those websites for Ruby installation and set-ups. It is as simple as just typing a couple of lines on Terminal if you are on Linux-based-OS, or even you may not need to install in case it is already installed on your operating system.
Firstly, open a terminal and use ‘rib’ commend to get into the Ruby interpreter. You may find it different from other IDE, in fact, this is not IDE at all. However, this is the easiest way to test your code or try out some code quickly.
Basic operators from other languages work almost the same way.
+ – / * (addition, subtraction, multiplication, division)
** (exponent)
% (remainder)
#null type is called “nil” in Ruby.
There are some basic classes that are useful to know.
Integer – integer type
methods: +, -, /, *, %, **, to_s, to_f
Float – float type (decimal)
methods: +, -, /, *, %, **, to_s, to_i
String – text type
methods: capitalise, reverse, length, upcase, to_i, to_f
To use method with a class, it is simple as the following.
“hello”.capitalize
=> “Hello”
(This is “hello” object of String class and the object used ‘captalize’ method like putting ‘.methodName’ in front of the class object.
*To know more about methods of some classes, just use ‘ri’ commend on Terminal window.

If you have some experience on programming especially based on linux kind operating systems (Ubuntu, Mac OS X, so on.), you will find Ruby easy to get familiar with and very simple to use. This article is just for those who have some programming knowledge or experience such as Java, C#, VB.NET, C, C++ or even Objective-C, assuming that you are somewhat familiar with the concept of OOP and basic idea of programming language.
Ruby is quite not the same as those legendary language like C or java. It is very interactive and simple. If you are using Mac OS X, you already have Ruby development environment. Most of linux OS also include any necessary development tools. – You can find further information on some other many websites that can be found by googling. (i.e. http://www.ruby-lang.org)I will let you look up those websites for Ruby installation and set-ups. It is as simple as just typing a couple of lines on Terminal if you are on Linux-based-OS, or even you may not need to install in case it is already installed on your operating system. Firstly, open a terminal and use ‘rib’ commend to get into the Ruby interpreter. You may find it different from other IDE, in fact, this is not IDE at all. However, this is the easiest way to test your code or try out some code quickly.
Basic operators from other languages work almost the same way. + – / * (addition, subtraction, multiplication, division)** (exponent)% (remainder)
#null type is called “nil” in Ruby.
There are some basic classes that are useful to know. Integer – integer type  methods: +, -, /, *, %, **, to_s, to_fFloat – float type (decimal) methods: +, -, /, *, %, **, to_s, to_iString – text type methods: capitalise, reverse, length, upcase, to_i, to_f
To use method with a class, it is simple as the following. “hello”.capitalize=> “Hello”(This is “hello” object of String class and the object used ‘captalize’ method like putting ‘.methodName’ in front of the class object.*To know more about methods of some classes, just use ‘ri’ commend on Terminal window.

** For more basic and detailed information, please refer to the website http://www.ruby-lang.org/en/

(There are some tutorials for beginners)

— coming up next: your own methods and classes

Advertisements

C# Polymorphism

Ok, this is very basic stuff (i mean concept.:D ) but also important. Polymorphism provides a way for a subclass (child class) to define its own version of a method defined by its base class (parent class). This is called “method overriding” and is very common concept in OOP (Object Oriented Programming) such as Java.

Let’s see how this concept works within C#. To re-build your current design, you need to understand the modifiers; virtual and override keywords, and their meanings. Overriding methods in C# is a bit different from doing so in Java, however, the main concept of it remains the same.

If a super class (base class) wishes to define a method that may be (or may be not) overridden by a subclass, it must mark the method with the virtual keyword. These methods with the virtual keyword are called virtual methods.

public class ClassName

{

// This method can be overridden by a derived class.

public virtual void VirtualMethodName(int paraInt)

{

}

}

The same rule is applied to a subclass. When a subclass wishes to change the implementation details of a virtual method, it does so using the override keyword.

class Subclass : SuperClass

{

public override void Method1(int intV)

{

….

base.Method1(10);

}

….

}

Unlike Java, you can leverage the default behavior using the base keyword. In this way (the same as the Java overriding concept, but for those who are new OOP with C#), there is no need to completely re-implement the logic behind Method1(), but can reuse and extend the default behavior of the parent class.