2. What is Ruby
• Programing language
• Dynamic
• Multi‑paradigm: OOP, functional,
imperative, reflection
• Influenced by: Perl, Smalltalk, Lisp,
C++, Python ...
• Created in the mid‑1990s
• "I wanted a scripting language that was more Yukihiro Matsumoto (Japan)
powerful than Perl, and more object‑oriented than Python. That's why
I decided to design my own language."
helper2424@gmail.com 2
3. Deeper in the Ruby
• Latest stable version 1.9.3‑p286
• RoR 3.0 has bugs with Ruby 1.8.7 p248 and p249
• RoR 3.0 has conflicts with 1.9.1
• Use RoR 3.x with Ruby 1.9.>=2
• Ruby License
helper2424@gmail.com 4
4. Philosophy
• Everything is object (numbers, primitives,
methods and classes too)
• Every object has class and superclass
• The root of class hierarchy is Object
• Ruby has not static methods or variables
• All instance variables are private
• Interfacejava mechanism through modules
• Module (like class, but) has not variables
helper2424@gmail.com 5
7. Little bit of syntax
#One line comments
=begin multiline comments (=begin and =end in one
column)
=end
'It's string' and "It's string" and %q!It's string too!
a # variable
$b # global variable
@c # instance variable
Constant # but u can change it if bribe conscience
helper2424@gmail.com 7
8. Functions
def this_function()
#function_body
end
def this_function
#function_body
end
def ==(variable)
#overload operator
end
helper2424@gmail.com 8
9. Classes
class Your_class
@test # by default private
def test_method #by default public
#code
end
private #yep, private modificator like in C++
def test_method2 #private
#code
end
public
def test_method # public
#code
end
end
helper2424@gmail.com 9
10. Code blocks
def test
print "<<"
yeild "Wolrd"
end
test do |x|
print " Hello #{x} ! >>"
end
# result << Hello World ! >>
helper2424@gmail.com 10
16. Additional literature
• Russ Olsen "Design Patterns In Ruby" : patterns
for rubists
• William C. Wake, Kevin Rutherford "Refactoring
in Ruby" : all in name
• Jay Fields, Shane Harvie, Martin Fowler
"Refactoring: Ruby Edition" : Fowlers's
"Refactoring" with examples for Ruby
helper2424@gmail.com 13