Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Ruby Language

overview
By: mohamad amin Rastgoo
The History of Ruby

 created by Yukihiro Matsumoto (more


affectionately known as Matz) in Japan
 Perl, Lisp, and Smalltalk,python
Philosophy
●No Perfect Language
● have joy

● computers my servants, not my masters

● least surprise

● unchangeable small core (that is,

syntax) and arbitrary extensible


class libraries
Domains
➢ Text processing
➢ CGI programming

➢ Network programming

➢ GUI programming

➢ XML programming

➢ Prototyping

➢ Programming education
Ruby Attribs
● Multi-paradigm programming language
● Methods: Every procedure in Ruby is a method of some
object.
● Blocks: blocks can be passed as a parameter to a
method
● No Declarations: variables distinguished by the prefix
of its name
Ruby Attribs
● Scope Prefix
● Inheritance and Mix-in
● Performance
● everything is open!
● Missing unary operators
● parallel assignment
● Mutable Strings
● True and false in Ruby
example
Classic Hello world example:

methods as objects: method(:puts).call "puts is an object!"


# => puts is an object!

The two syntaxes for creating a code block:


example
Comparison with Python
Similarities:
● Interactive prompt(irb)

● No special line terminator

● Lists Brackets and dicts(hashes) braces

● Arrays

● Objects Strongly and dynamically typed

● Every thing is object


Comparison with Python
Differences:
● More Speed !!!

● Mutable Strings

● Constants

● enforced case-conventions

● only one kind of list container

● No direct attrib access

● public, private, and protected to enforce

access
● Mixin's inheritance

● Open classes
Type system
Type Safe?
1.no operation will be applied to a variable of a
wrong type: probably safe
2.the program will not have type errors when it
runs:No
Type system -Strong Typed?
1.type annotations are associated with variable names,
rather than with values. If types are attached to values, it is
weakly typed: WEAKLY TYPED

2. if it contains compile-time checks for type constraint


violations. If checking is deferred to run time, it is weakly
typed. WEAKLY TYPED
Type system -Strong Typed?
3.there are compile-time or run-time checks for type
constraint violations. If no checking is done, it
weakly typed.STRONGLY TYPED
4. conversions between different types are forbidden.
If such conversions are allowed, it is weakly
typed.WEAKLY TYPED
Type system -Strong Typed?
5.conversions between different types must be
indicated explicitly. WEAKLY TYPED

6.there is no language-level way to disable or evade


the type system. If there are casts or other type-
evasive mechanisms, it is weakly typed. strongly
typed, but very difficult to prove mathematically.
Type system -Strong Typed?
7.has a complex, fine-grained type system with
compound types. If it has only a few types, or only
scalar types, it is weakly typed.STRONGLY TYPED

8.the type of its variables is fixed and does not vary


over the lifetime of the variable. If the type of the
datum stored in a variable can change, the language
is weakly typed. WEAKLY TYPED
Refrences
http://www.informit.com/articles/article.aspx?p=18225&
http://www.rubytips.org/2008/04/07/10-unique-ruby-lang
3.Programming in Ruby ,Dave Thomas ,Andy
Hunt,September 13, 2000
4.http://ruby-lang.org
5.http://www.ruby-lang.org/
6.http://www.techotopia.com/Ruby_Essentials.htm
Any Question?

You might also like