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?
[Link] operation will be applied to a variable of a
wrong type: probably safe
[Link] program will not have type errors when it
runs:No
Type system -Strong Typed?
[Link] 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?
[Link] are compile-time or run-time checks for type
constraint violations. If no checking is done, it
weakly [Link] TYPED
4. conversions between different types are forbidden.
If such conversions are allowed, it is weakly
[Link] TYPED
Type system -Strong Typed?
[Link] between different types must be
indicated explicitly. WEAKLY TYPED
[Link] 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?
[Link] a complex, fine-grained type system with
compound types. If it has only a few types, or only
scalar types, it is weakly [Link] TYPED
[Link] 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
[Link]
[Link]
[Link] in Ruby ,Dave Thomas ,Andy
Hunt,September 13, 2000
4.[Link]
5.[Link]
6.[Link]
Any Question?