0% found this document useful (0 votes)
31 views

Ruby

Ruby is a dynamically typed language where variables start with $, strings can be interpolated with #{variable}, and everything is an object. Modules define reusable code and can be mixed into classes, providing a namespace. Variables hold references to objects and assigning with = copies the reference, so objects need to be cloned to prevent changes from affecting other references. Constants are convention rather than enforced, and modifying an existing constant issues a warning. Control structures include if/unless/elsif, case/when/then, and loops like while, for, and until.

Uploaded by

RadaBogdanRaul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Ruby

Ruby is a dynamically typed language where variables start with $, strings can be interpolated with #{variable}, and everything is an object. Modules define reusable code and can be mixed into classes, providing a namespace. Variables hold references to objects and assigning with = copies the reference, so objects need to be cloned to prevent changes from affecting other references. Constants are convention rather than enforced, and modifying an existing constant issues a warning. Control structures include if/unless/elsif, case/when/then, and loops like while, for, and until.

Uploaded by

RadaBogdanRaul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

#!

/usr/bin/ruby

print Hello Ruby

Yukihiro (Matz) Matsumoto

PHP.rb
- dynamically typed
- controll access : public, protected and
private
- some vars start $
- string interpolation and : #{foo}
- true, false
- [] ...

just that
-

null is called nil


need to convert between types
(), return, are optional
no abstract classes or interfaces
{} and [] are not interchangeable
false, nil => FALSE
0, [], {} and => TRUE

Everything is an Object
class Numeric < Parintele
def to_square
self * self
end
end
2.to_square => 4

Modules and Mixins


- modules define reusable pieces of code
that couldnt be instantiated.
- modules provides a namespace
- modules could be mixin to any class
that satisfy : Should quack and swim like a
duck.

codingguidelines
- localVariable
-@instanceVariable
-@@classVariable
-$globalVariable
-CONSTANT
-ClassName

special slide for ...


VLAD

method_name

Ruby variables hold references to objects


and the = operator copies the references.
In order to get a object that won't change
out from under you, you need to dup or
clone the object you're passed, thus giving
an object that nobody else has a reference
to.

Constants are little more than a


convention. If you try to modify a constant
that's already been assigned to, you'll get a
warning. More or less, Ruby sees them as
no different from any other variable, and
when you try to assign to any variable that
begins in a capital letter and already
exists, it prints a warning on standard
error.

if/unless/ ELSIF
case/when/then

Loops - while, for, until, break, redo and


retry

You might also like