rubyx

prettybadelyngeΛογισμικό & κατασκευή λογ/κού

18 Νοε 2013 (πριν από 3 χρόνια και 6 μήνες)

64 εμφανίσεις

Ruby

Ruby


Overview:



Object
-
oriented scripting language



Developed by Yukihiro Matsumoto


Ruby


Features:


Pure object
-
oriented language:


Every value in Ruby is an object, even the most
primitive things: strings, numbers and even true and
false


Methods are always called on an object


Example
:
-
233.abs
vs.

Math.abs(
-
233)
in Java


Ruby


Features:


Dynamic:


Everything in a program are built by the code when it
run
-

Interpreted


A program can also modify its own definitions while it’s
running.


Variables in Ruby are
dynamically typed:



v
ar1 = “hello”

Var
2 = 5

var1 = 65

Ruby


Features:


Singleton Classes:


Every object has two classes : a “regular” class and a
singleton class


Singleton class is a nameless class whose only instance
is that object


Methods can be added to a singleton class, which can
then be called on the lone object belonging to them.



Ruby


Features:


Singleton Classes:


Example:

foobar

=
Array.new

foobar.class

=> Array

foobar.size

=> 0


Add methods:

def
foorbar.size



“hello world”

end

f
oobar.size

=> “hello world”


Ruby


Features:


Flexibility:


Methods can be added to existing classes without sub
-
classing


Operators can be overloaded


The behavior of the standard library can be redefined
at runtime.



Ruby


Features:


Variables and Scope:


You do not need to declare variables or variable scope
in Ruby.


The name of the variable automatically determines its
scope.


Example :


$x

: global variable


x
: local variable


@x

: instance variable


@@x

: class variable



Ruby


Features:


Blocks


One of Ruby’s most unique.


The code in the block is not evaluated right away, it is
packaged into an object,
which is called at anytime just
like a method.


A block object can be stored in a variable, passed along
to other methods, or even copied.




Ruby


Features


Advanced Features


Exceptions for error
-
handling



OS
-
independent threading, which allows you to write
multi
-
threading applications even on operating systems
such as DOS.

Ruby and Rhodes


Rhodes development architecture:


Model : ORM (object relational manager),
Rhom


User Interface : HTML, CSS


Logic of views: ERB (embedded ruby)


Controller: Ruby