Hi I'm Ashik Ajith
ashikajith@gmail.com
Purpose
- Getting Started with Ruby
- Having Fun with Ruby (Hope so...)
- Not a Tutorial :-(
Why Ruby ??
- Ruby is one of the easiest language to learn
Why Ruby ??
- Ruby is one of the easiest language to learn
#include <iostream>
int main()
{
std::cout << "hello world!\n";
return 0;
}
Why Ruby ??
- Ruby is one of the easiest language to learn
print "Hello World!"
Why Ruby ??
- Ruby is one of the easiest language to learn
print "Hello World!"
p "Hello World!"
Why Ruby ??
-
Ruby is one of the easiest language to learn
- Ruby is Natural to read and easy to write
Why Ruby ??
-
Ruby is one of the easiest language to learn
- Ruby is Natural to read and easy to write
5.times { print "Why so serious !!" }
Why Ruby ??
-
Ruby is one of the easiest language to learn
-
Ruby is Natural to read and easy to write
-
Ruby is Flexible and focus on Simplicity and Productivity
Why Ruby ??
- Active open source community for supporting
Why Ruby ??
- Active open source community for supporting
- High demand for Ruby developers
Why Ruby ??
- Active open source community for supporting
-
High demand for Ruby developers
- Stepping to Ruby on Rails
- Rails is nothing but a web application frame work written in Ruby
Okay Then Whats Rails ??
- Rails is nothing but a web application frame work written in Ruby
- David Heinemeier Hansson extracted Ruby on Rails from his work on the project management tool Basecamp
Okay Then Whats Rails ??
- Rails is nothing but a web application frame work written in Ruby
-
David Heinemeier Hansson extracted Ruby on Rails from his work on the project management tool Basecamp
- Released on July 2004 to open source. Give commit rights to project on February 2005
Okay Then Whats Rails ??
Okay Then Whats Rails ??
Okay Then Whats Rails ??
Okay Then Whats Rails ??

What about Ruby
- Project management web application Basecamp
What about Ruby
- Project management web application Basecamp
- Motorola uses Ruby to script a simulator to generate scenarios and to post process the data
What about Ruby
- Project management web application Basecamp
-
Motorola uses Ruby to script a simulator to generate scenarios and to post process the data
- Google SketchUp is a 3D modeling application that uses Ruby for its macro scripting API
What about Ruby
- Project management web application Basecamp
-
Motorola uses Ruby to script a simulator to generate scenarios and to post process the data
-
Google SketchUp is a 3D modeling application that uses Ruby for its macro scripting API
- At MORPHA project, Ruby was used to implemented the reactive control part for the Siemens service robot.
What about Ruby
source:https://www.ruby-lang.org/en/
What about Ruby

History of Ruby (walk through)

- Yukihiro Matsumoto (Ruby Matz)
History of Ruby (walk through)
- Aim to create a OO Scripting Language
-
A language that is more powerful than Perl, and more object-oriented than Python
-
Code-named after a gemstone's name (àla Perl)
- Released in 1995(v 0.95) -
- Current Version - Ruby (v2.2.3)
Install Ruby
#For Ubuntu
-
https://www.ruby-lang.org/en/documentation/installation/
-
https://gorails.com/setup/ubuntu/14.10(recommended)
Install Ruby

Install Ruby
#For Ubuntu
-
https://www.ruby-lang.org/en/documentation/installation/
-
https://gorails.com/setup/ubuntu/14.10(recommended)
#For Mac and Windows Users
Install Ruby

"Programming languages must feel natural to programmers."
- Matz, creator of Ruby
Lets Say "Hello" to Ruby
puts "Hello World"
#=> "Hello World"
my_input = gets #=> Accept the input as string
Ruby Strings
puts "Lets have some fun"
#=> "Lets have some fun"
# Reverse a string
# Capitalize (with !)
# Concatenate (+)
# Upcase
# Downcase
# Splitting
# gsub, sub
Ruby With Numbers
#irb console
2 + 2 #=> 4
2 + 7.14 #=> 9.14
2 - 5.12 #=> -3.12
2 ** 100 #=> 1267650600228229401496703205376
2 / 5 #=>
2 / 5.0 #=>
Ruby With Objects
#irb console
x = 4
x.class #=> Fixnum
x = 3.142857
x.class #=> Float
x = (2 ** 100)
x.class #=> Bignum
puts "I can inject variables here #{x} " #=> Use double quotes
Ruby With Arrays
#irb console
list = ['a','b','c','d']
list << 'e'
list.pop #=> "e"
list #=> ["a", "b", "c", "d"]
list.push 4 #=> ["a", "b", "c", "d", "4"]
# sort
# insert(pos, ary_elemnt)
# delete_at(index)
Ruby With Ranges
#irb console
# Exclusive Range
numbers = (1...6)
alphabets = ('a' ... 'j')
range_set = ('abc' ... 'abz') #=> ?
# Inclusive Range
numbers = (1 .. 6)
alphabets = ('a' .. 'j')
Ruby With Hashes
Hash = {key => value}
hash = {1=> 'one', 2=> 'two', 3=>'three'}
hash[1] #=> 'One'
hash[2] #=> 'Two'
another_hash = { 'a' => 1, 'b' => 2, 'c' => 3 }
another_hash.keys #=> ["a", "b", "c"]
another_hash.values #=> [1, 2, 3]
A Hash is a collection of unique keys and values, Similar to arrays but can use any object type
Ruby With Hashes (Contd..)
#Can Have the values as hash instead of String
vehicles = { 'bikes' => {
'honda' => ['CB Uniconorn', 'Dream Yuga', 'Activa'],
'royal_enfield' => ['Bullet Classic', 'Deset Storm',
'Thunder bird']
},
'cars' => {
'Ford' => ['Ford Figo', 'Ford Classic']
}
}
vehicles['bikes']['royal_enfield'] #=> ['Bullet Classic', 'Deset Storm',
'Thunder bird']
Ruby With Conditions
if condition
#do something
elsif
#do something else
end
do_something if condition
unless condition
#do something
else
#do something else
end
#do somthing unless condition
Ruby With Conditions
Switch Statement
age = 5
case age
when 0 .. 2
puts "between 0 & 2"
when 3 .. 6
puts "between 3 & 6"
when 7 .. 12
puts "between 7 & 12"
when 13 .. 18
puts "between 13 & 18"
else
puts "No Idea"
end
Ruby With Conditions
While
i = 0
num = 5
while i < num do
puts("Inside the loop i = #i" )
i +=1
end
For
for i in 0..5
puts "Value of local variable is #{i}"
end
Ruby With Conditions
array_or_range.each do |value|
puts value
end
3.times do
print 'ha'
end
array_or_range.map{|e| e }
array_or_range.map{|e| e*2 }
map with select odd or even
Ruby With Classes and Objects
class Dog
def greet
'Woof!'
end
end
dog = Dog.new
dog.greet #=> 'Woof!'
Ruby With Constructors and Variables
class Robot
def initialize(name)
@name = name
end
def say_hello
"Hi, I'm #{@name}"
end
end
robo = Robot.new 'Eva'
robo.say_hello #=> 'Hi, I'm Eva.'
class Cat
@@sound = 'Meow' #Class variable
def greet
@@sound
end
end
garfield = Cat.new
garfield.greet #=> 'Meow!'
Lets Check what we got !!!
# Creating a plus method
2.plus 2 #=> 4
3.plus 5 #=> 8
# Override a reverse method
'Transform'.reverse #> 'Transform' or #some_other_msg
# What about Infinity
1/0 #=> Error or Infinity ?
#Initialize a hash with a list
Hash['key1', 'value1', 'key2', 'value2'] #=> {"key1"=>"value1", "key2"=>"value2"}
Hash[1,2,3,4,5,6] #=> {1=>2, 3=>4, 5=>6}
Lets Check what we got !!!
# Double pipes instead of if condition
a = nil
b = 12
a = a || b #=> ?
# Multiplication with Array
[1, 2, 3] * 3 #= [1, 2, 3, 1, 2, 3, 1, 2, 3]
# Array Flatten
[1,2,3,4,[6,7,8,9],11,12].flatten
%w(Tom Dick Harry)
%x(execute shell command)
%Q(dispaly string with double quotes)
What we have discussed so far..
- What's Ruby
- What is Rails (Web applicationFrame Work built in Ruby)
- Use of Ruby and Rails
- Familiarizing with String, Operators and other Data types in Ruby
- Creating and Overriding the Methods in Ruby
We have Python, PHP..then why Ruby
- There is nothing like perfect programming language
We have Python, PHP..then why Ruby
- There is nothing like perfect programming language
- Ruby is partially famous because of the Rails Frame work
We have Python, PHP..then why Ruby
- There is nothing like perfect programming language
-
Ruby is partially famous because of the Rails Frame work
- With Rails you can build web application much more faster compare to other Technologies.
- Have the active open source community
Ruby Community Groups
- Bangalore Ruby user group (http://bangaloreruby.org/)
- Kerala Ruby user group(https://krug.github.io/)
- Mumbai Ruby User Group
- Ruby Forum (https://www.ruby-forum.com/)
Available Resources for Ruby
-
Try Ruby! (http://tryruby.org/)
-
Ruby in Twenty Minutes
(https://www.ruby-lang.org/en/documentation/quickstart/)
-
Ruby Monk (https://rubymonk.com/)
QUESTIONS ??
deckhalf
By Ashik Ajith
deckhalf
- 1,010