Ruby is a scripting language created in 1993 by Yukihiro "Matz" Matsumoto who wanted a language more powerful than Perl but more object-oriented than Python. It uses classes and objects, with everything in Ruby represented as an object. Variables, methods, classes, modules, integers and constants are all objects. Ruby includes common data structures like arrays and hashes, and supports procedural and object-oriented programming. It is interpreted, making it useful for scripting, web development and rapid application development.
2. History
01
0
2
03
Yukihiro “Matz” Matsumoto
February 24, 1993
Matz wanted a scripting language that was more
powerful than Perl, and more object-oriented than
Python. That's why he decided to design his own
language.
Perl Java Python Ruby PHP
1987 1991 1993 1995
4. Scripting Language
A high-level programming language that is interpreted by
another program at runtime rather than compiled by the
computer's processor as other programming languages
(such as C and C++) are. Scripting languages, which can
be embedded within HTML, commonly are used to add
functionality to a Web page.
JavaScript, ASP, JSP, PHP, Perl, Tcl and Python are
examples of scripting languages.
8. Variables
Below given are examples of valid variable names
orange total_price orange_ _orange
buyGift doing747 geting_747 iam23yrsold
Below are given examples of invalid variable names
34signals
Mango
total cost
9. Everything is an object
1.class # => Fixnum
'a'.class # => String
:a.class # => Symbol
class Record
end
Record.class # => Class
Record.new.class # => Record
10. Method, Class and Invocation
def do_work(task_ref)
task_ref.assigned_work
end
Class Task
def assigned_work
puts “Completed successfully.”
end
end
do_work(Task.new)
Method
Class
Invocation
15. Loops
for count in 1..10 i = 1
print count, " Hellon“ count = 10
end until i > count do
print i, " Hellon"
(1..10).each do |count| i+=1
print count, " Hellon" end
end
i = 1 5.times { puts “hi” }
count = 10
while i <= count do
print i, " Hellon"
i +=1
end