Ruby Presentation Sample
Ruby Presentation Sample
by Kostas Platis
“ I HOPE TO SEE RUBY HELP EVERY PROGRAMMER IN
THE WORLD TO BE PRODUCTIVE, AND TO ENJOY
PROGRAMMING, AND TO BE HAPPY. THAT IS THE
PRIMARY PURPOSE OF RUBY LANGUAGE.
wikipedia.com
Ruby is a dynamic programming language
OBJECT-ORIENTED
Ruby is pure object-oriented language and everything appears to
Ruby as an object
Even a class itself is an object that is an instance of the Class class
Ruby is based on the concept of “objects” , classes , attributes and
methods.
GENERAL PURPOSE
• Server-Side(Ruby-on-Rails)
• Web Servers
• Common GUI Applications
• Low-Level systems
Simulations
NASA Langley Research Center uses Ruby to conduct simulations.
3D Modeling
Google SketchUp is a 3D modeling application that uses Ruby for its macro scripting API.
Robotics
At MORPHA project, Ruby was used to implemented the reactive control part for the
Siemens service robot.
Web Applications Implemented in Rails
Windows
1) Open www.rubyinstaller.org
2) Download Ruby 2.2.3
3) Install RubyInstaller
RUBY GEMS
As most programming languages, Ruby offers a wide set of third-
party libraries.
Most of them are released in the form of a gem
Windows
RVM is not developed for Windows. An alternative is pik
(https://github.com/vertiginous/pik)
IRB
Interactive Ruby Shell (IRB or irb) is a REPL for programming in Ruby. The
program is launched from a command line and allows the execution of
Ruby commands with immediate response, experimenting in real-time.
RubyMine Installation
1. https://www.jetbrains.com/ruby
2. Download and install RubyMine
3. Create JetBrains Account
4. Apply for Student licence in www.jetbrains.com/student
5. Open RubyMine and login using your account
IN GENERAL
• Ruby files use the suffix .rb
• Comments start with #
• Multiple line comments use =begin , =end
• nil(null in other programming languages) means that the
object is an instance of the Nil Class
• Blocks end using the “end” statement
• Variables dynamically change their type
NAMING
Ruby has some strange naming conventions
Inheritance is a thing
Multiple Inheritance is not
objectTitle = ClassName.new(param1,param2…)
METHODS
def method_name(param_1,param_2...)
<code>
<code>
<code>
end
• “return” is not necessary. The returned value is the latest
changed variable
• Method block ends with “end”
STRING
CHARACTERISTICS
• “\n” is used as line breaker
• If we want to use a variable name inside a string we just
add #{variable_name}
• Alternatively, we can use the + operator in order to unite 2
or more strings
• Double quote vs Single quotes : Double quotes allow you
to do string interpolation
ARRAYS
• Arrays, like variables, dont need initialization
• temp = Array.new(10)
• puts temp.size or puts temp.length
• We can save variables of different type
• Values are saved as A = ['A','B','C'] or A[0] = 1 etc
SHORTCUT %w
%w is used in order to initialize arrays alternatively,
A = %w{ A B C }
HASHES
• To initialize Hashes we use curly braces instead of braces
• In order to initialize a map :
"key => value"
Note : keys are unique, values are not
• temp = Hash.new
Hash Display
temp[:key]
If key does not exist, nil is returned
CONDITIONAL
STRUCTURES
• main body does not require curly braces { }
• Condition does not require parentheses
• If main body contains only one command, the command
can go before the condition
• Conditional structures are :
if-elsif-else,
Case-when (like switch-case)
unless-else
LOOPS
• main body does not require curly braces { }
• Condition does not require parentheses
• Known loops are :
1. while[condition]-end, begin-while[condition]
2. begin – end until [condition]
3. for i in 0…j
next : is used in order to pass to the next value
redo : restarts the iteration of the most internal loop,
without checking loop condition.
If retry appears in rescue clause of begin expression,
restart from the beginning of the 1begin body.
CODE BLOCKS
Ruby includes a pretty cool feature : The Code Blocks
{|arg1,arg2| code_including_args}
CODE BLOCKS
Yeah…ok but whats the usage?
NoMemoryError
ScriptError
StandardError
SystemExit
SystemStackError
WHY RUBY?
1. Ruby allows the programmer to do things fast (less code – but
takes time to learn). That’s why Ruby programmers are happy
2. Open-Source (Hundreds of recourses – everything is free! –
gems usage)
3. Everything is free! Gems usage save time and money
4. Ruby On Rails (Rails conventions)
RESOURCES
www.ruby-lang.org (Ruby Official Site)
www.tutorialspoint.com/ruby (Examples provider)
www.rubylearning.com (Useful Tutorials)
www.rubyinstaller.org (Installer for Windows)
www.jetbrains.com/ruby (RubyMine IDE)
THANK YOU!
Kostas Platis
Email : [email protected]
Slideshare : www.slideshare.net/platico_dev