Why Ruby? 
{ 
my story how I started learning and using Ruby
Plan 
1. About me 
2. Why Ruby? 
3. What is Ruby? 
4. Ruby on Rails 
5. Ruby-world Ecosystem 
6. Future 
7. Questions
About me 
Igor Kasyanchuk 
Education: National University of Oil and Gas, PZ-01-1 
Worked at: Eleks, SoftServe, freelancing, own projects 
Completed projects: 20+ 
Used: Java, Visual C++, C++ Builder 
Using: Ruby, Ruby on Rails, HTML/CSS/JS/etc 
Working now: in SoftServe as Ruby, Ruby on Rails Team/Tech Lead
Why Ruby? 
I was tired of … 
... and many other things
Why Ruby? 
And I met Ruby … 
say = "I love Ruby" 
puts say 
say['love'] = "*love*" 
puts say.upcase 
5.times { puts say }
What is Ruby? 
Ruby is a dynamic, reflective, object-oriented, 
general-purpose programming 
language. It was designed and developed in 
the mid-1990s by Yukihiro "Matz" 
Matsumoto in Japan. 
… from Wikipedia 
Q: What other dynamic languages do you know?
What is Ruby? 
Ruby is a dynamic, reflective, object-oriented, 
general-purpose programming 
language. It was designed and developed in 
the mid-1990s by Yukihiro "Matz" 
Matsumoto in Japan. 
… from Wikipedia 
What other dynamic languages do you 
know? – PHP, Python, Node.JS
Ruby is 
• Dynamic programming language 
• Less is more, efficient code, easy to read, elegant 
• One of the best language for creating startups (Twitter, 
Groupon, Airbnb, Slideshare) 
• Companies using it: HP, Twitter, Intel, NASA, HULU, Groupon, 
Airbnb, Github, Slideshare 
• Has ~90K libraries, which were downloaded ~3.8M times 
• Killer app: Ruby on Rails
Also, Ruby is 
http://hyperpolyglot.org/scripting 
PHP 
$a = [1, 2, 3] 
min($a) 
max($a) 
Python 
min([1, 2, 3]) 
max([1, 2, 3]) 
Ruby 
[1, 2, 3].min 
[1, 2, 3].max 
Java 
import java.util.Arrays; 
import java.util.Collections; 
import org.apache.commons.lang.ArrayUtils; 
public class MinMaxValue { 
public static void main(String[] args) { 
char[] a = {'3', '5', '1', '4', '2'}; 
List b = Arrays.asList(ArrayUtils.toObject(a)); 
System.out.println(Collections.min(b)); 
System.out.println(Collections.max(b)); 
} 
}
Syntax 
1. Overview 
2. Loops 
3. Blocks 
4. Classes, Mixins 
5. OOP in Ruby 
6. “Dynamicity”
Overview 
puts "Hello World" 
"LOREM".downcase 
"lorem".length 
"abcd".split("") 
if /1999/.match(s) 
puts "party!" 
end 
t = Time.now 
a = [1, 2, 3, 4] 
a[-1] 
Time.now.strftime("%Y-%m-%d %H:%M:%S") 
role = :admin 
ROLES = [‘admin’, ‘user’] 
(1..1_000_000).each do |i| 
… 
end 
x = 1000 
user = user.new unless user
Loops 
i=0 
while i < 3 
print i, " whilen” 
i += 1 
end 
for ss in 0..2 
print ss, " for doubledotn” 
end 
array=['zero', 'one', 'two', 'three', 'four', 'five'] 
array.each{|ss| print ss, " array.eachn"} 
array[0,3].each{|ss| print ss, " array_first_three.eachn”}
Blocks 
def simple 
puts 'Here comes the code block!’ 
yield 
puts 'There was the code block!’ 
end 
Now: 
simple { puts 'Hooray! The code block is here!' } 
Result: 
Here comes the code block! 
Hooray! The code block is here! 
There was the code block!
Classes, Mixins 
class Greeter 
def initialize(name) 
@name = name.capitalize 
end 
def salute 
puts "Hello #{@name}!" 
end 
end 
# Create a new object 
g = Greeter.new("world") 
# Output "Hello World!" 
g.salute 
# Creating mixin 
module Log 
def log(message) 
puts message 
end 
end 
# Creating class 
class User 
include Log 
end 
user = User.new 
user.log “hello user”
OOP in Ruby 
1. Everything is an object (numbers, strings, classes, everything…) 
2. Class can inherit only from one parent (single inheritance) 
3. You can use mixins (in other languages eq. to interfaces + implementation) 
5.times do |e| 
puts “hello world” 
end 
[1,0,6,9,3,5].select{|e| e > 3}.collect{|e| e*2}.min.times do |e| 
puts e 
end
“Dynamicity” 
class Greeter 
def initialize(name) 
@name = name 
end 
def method_missing(e) 
greeting = e.to_s.capitalize 
"#{greeting} #{@name}" 
end 
end 
g = Greeter.new("Igor") 
puts g.hello 
=> Hello Igor 
1. Strong reflection 
2. eval 
3. method_missing 
4. send 
5. overload, override anything 
6. modify, remove, add methods on the fly
Ruby on Rails 
Ruby on Rails, or simply Rails, is an open 
source web application framework written 
in Ruby. Rails is a full-stack framework that 
emphasizes the use of well-known software 
engineering patterns and paradigms, 
including convention over configuration 
(CoC), don't repeat yourself (DRY), the active 
record pattern, and model–view–controller 
(MVC). 
… Wikipedia 
Author: 
David Heinemeier Hansson 
Since 2004 
From Denmark
Ruby on Rails 
1. Built on Ruby 
2. Web Application Framework 
3. Blog in 15 minutes 
4. MVC, CoC, DRY
Built on Ruby 
To work with Ruby on Rails you just need to 
install Ruby our your computer and then 
install ”rails” as gem. 
gem install rails
Web Application Framework 
• HTML/HAML/SLIM… 
• CSS/SCSS/SASS… 
• JS/CoffeeScript…. 
• MySQL/Postgres/Mongo…. 
• REST/API 
• Testing 
• Java, C, Resque, Sphinx, ElasticSearch, etc
Blog in 15 minutes 
Check it!
Blog in 15 minutes 
Check it!
MVC 
• Object Relation Mapping 
• Database Agnostic 
• CRUD simple 
• Class to Table, Row to Object 
class User < ActiveRecord::Base 
has_many :photos 
end 
User.first => SELECT `users`.* FROM `users` ORDER BY `users`.`id` ASC LIMIT 1 
User.find(2) => SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1 
User.find_by(first_name: "igor") => 
SELECT `users`.* FROM `users` WHERE `users`.`first_name` = 'igor' LIMIT 1 
user = User.find(1) 
user.photos => SELECT photos.* from photos where user_id = 1
MVC 
Connecting view and model 
сlass UsersController < ApplicationController 
def index 
@users= User.all 
end 
end
MVC 
Generating HTML (using SLIM) 
table 
- @users.each do |user| 
tr 
td= user.first_name 
td= user.last_name
CoC 
Convention over Configuration
DRY 
# def easy_ui 
# self.easy.presence || 'EASY' 
# end 
# def medium_ui 
# self.medium.presence || 'MEDIUM' 
# end 
# def hard_ui 
# self.hard.presence || 'HARD' 
# end 
[:easy, :medium, :hard].each do |field| 
define_method "#{field}_ui" do 
[field].presence || field.to_s.upcase 
end 
end
Ruby-world Ecosystem 
Interpreters: MRI, jRuby, Rubinius, … 
Frameworks: Ruby on Rails, Sinatra, E, … 
Editors: Sublime, RubyMine, VIM, … 
Tests: Rspec, Selenium, Capybara, minitest 
Servers: Passenger, Unicorn, Puma, Thin, … 
Libraries (gems): for any tasks … xml, video, image, data processing, 
API, …. 
Mobile App: RubyMotion – create native iOS apps in Ruby 
Community: Google groups, stackoverflow, rubyclub.com.ua, … 
And more …. Github, BitBucket, CoffeeScript, SASS/SCSS, 
HAML/SLIM, 
OAuth, Emails, Ajax, Books(30+), integration with Backbone (and 
other JS frameworks), payments (PrivatBank has gem), …
Future 
• Ruby 2.2 is coming 
• Rails 4.2 is coming + Rails 5 branch is created 
• Many job offers 
• New Projects, challenges, startups
Questions? 
skype: igorkasyanchuk 
feel free to contact me 
Thank you 
and welcome to Ruby world

Why Ruby?

  • 1.
    Why Ruby? { my story how I started learning and using Ruby
  • 2.
    Plan 1. Aboutme 2. Why Ruby? 3. What is Ruby? 4. Ruby on Rails 5. Ruby-world Ecosystem 6. Future 7. Questions
  • 3.
    About me IgorKasyanchuk Education: National University of Oil and Gas, PZ-01-1 Worked at: Eleks, SoftServe, freelancing, own projects Completed projects: 20+ Used: Java, Visual C++, C++ Builder Using: Ruby, Ruby on Rails, HTML/CSS/JS/etc Working now: in SoftServe as Ruby, Ruby on Rails Team/Tech Lead
  • 4.
    Why Ruby? Iwas tired of … ... and many other things
  • 5.
    Why Ruby? AndI met Ruby … say = "I love Ruby" puts say say['love'] = "*love*" puts say.upcase 5.times { puts say }
  • 6.
    What is Ruby? Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan. … from Wikipedia Q: What other dynamic languages do you know?
  • 7.
    What is Ruby? Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan. … from Wikipedia What other dynamic languages do you know? – PHP, Python, Node.JS
  • 8.
    Ruby is •Dynamic programming language • Less is more, efficient code, easy to read, elegant • One of the best language for creating startups (Twitter, Groupon, Airbnb, Slideshare) • Companies using it: HP, Twitter, Intel, NASA, HULU, Groupon, Airbnb, Github, Slideshare • Has ~90K libraries, which were downloaded ~3.8M times • Killer app: Ruby on Rails
  • 9.
    Also, Ruby is http://hyperpolyglot.org/scripting PHP $a = [1, 2, 3] min($a) max($a) Python min([1, 2, 3]) max([1, 2, 3]) Ruby [1, 2, 3].min [1, 2, 3].max Java import java.util.Arrays; import java.util.Collections; import org.apache.commons.lang.ArrayUtils; public class MinMaxValue { public static void main(String[] args) { char[] a = {'3', '5', '1', '4', '2'}; List b = Arrays.asList(ArrayUtils.toObject(a)); System.out.println(Collections.min(b)); System.out.println(Collections.max(b)); } }
  • 10.
    Syntax 1. Overview 2. Loops 3. Blocks 4. Classes, Mixins 5. OOP in Ruby 6. “Dynamicity”
  • 11.
    Overview puts "HelloWorld" "LOREM".downcase "lorem".length "abcd".split("") if /1999/.match(s) puts "party!" end t = Time.now a = [1, 2, 3, 4] a[-1] Time.now.strftime("%Y-%m-%d %H:%M:%S") role = :admin ROLES = [‘admin’, ‘user’] (1..1_000_000).each do |i| … end x = 1000 user = user.new unless user
  • 12.
    Loops i=0 whilei < 3 print i, " whilen” i += 1 end for ss in 0..2 print ss, " for doubledotn” end array=['zero', 'one', 'two', 'three', 'four', 'five'] array.each{|ss| print ss, " array.eachn"} array[0,3].each{|ss| print ss, " array_first_three.eachn”}
  • 13.
    Blocks def simple puts 'Here comes the code block!’ yield puts 'There was the code block!’ end Now: simple { puts 'Hooray! The code block is here!' } Result: Here comes the code block! Hooray! The code block is here! There was the code block!
  • 14.
    Classes, Mixins classGreeter def initialize(name) @name = name.capitalize end def salute puts "Hello #{@name}!" end end # Create a new object g = Greeter.new("world") # Output "Hello World!" g.salute # Creating mixin module Log def log(message) puts message end end # Creating class class User include Log end user = User.new user.log “hello user”
  • 15.
    OOP in Ruby 1. Everything is an object (numbers, strings, classes, everything…) 2. Class can inherit only from one parent (single inheritance) 3. You can use mixins (in other languages eq. to interfaces + implementation) 5.times do |e| puts “hello world” end [1,0,6,9,3,5].select{|e| e > 3}.collect{|e| e*2}.min.times do |e| puts e end
  • 16.
    “Dynamicity” class Greeter def initialize(name) @name = name end def method_missing(e) greeting = e.to_s.capitalize "#{greeting} #{@name}" end end g = Greeter.new("Igor") puts g.hello => Hello Igor 1. Strong reflection 2. eval 3. method_missing 4. send 5. overload, override anything 6. modify, remove, add methods on the fly
  • 17.
    Ruby on Rails Ruby on Rails, or simply Rails, is an open source web application framework written in Ruby. Rails is a full-stack framework that emphasizes the use of well-known software engineering patterns and paradigms, including convention over configuration (CoC), don't repeat yourself (DRY), the active record pattern, and model–view–controller (MVC). … Wikipedia Author: David Heinemeier Hansson Since 2004 From Denmark
  • 18.
    Ruby on Rails 1. Built on Ruby 2. Web Application Framework 3. Blog in 15 minutes 4. MVC, CoC, DRY
  • 19.
    Built on Ruby To work with Ruby on Rails you just need to install Ruby our your computer and then install ”rails” as gem. gem install rails
  • 20.
    Web Application Framework • HTML/HAML/SLIM… • CSS/SCSS/SASS… • JS/CoffeeScript…. • MySQL/Postgres/Mongo…. • REST/API • Testing • Java, C, Resque, Sphinx, ElasticSearch, etc
  • 21.
    Blog in 15minutes Check it!
  • 22.
    Blog in 15minutes Check it!
  • 23.
    MVC • ObjectRelation Mapping • Database Agnostic • CRUD simple • Class to Table, Row to Object class User < ActiveRecord::Base has_many :photos end User.first => SELECT `users`.* FROM `users` ORDER BY `users`.`id` ASC LIMIT 1 User.find(2) => SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1 User.find_by(first_name: "igor") => SELECT `users`.* FROM `users` WHERE `users`.`first_name` = 'igor' LIMIT 1 user = User.find(1) user.photos => SELECT photos.* from photos where user_id = 1
  • 24.
    MVC Connecting viewand model сlass UsersController < ApplicationController def index @users= User.all end end
  • 25.
    MVC Generating HTML(using SLIM) table - @users.each do |user| tr td= user.first_name td= user.last_name
  • 26.
    CoC Convention overConfiguration
  • 27.
    DRY # defeasy_ui # self.easy.presence || 'EASY' # end # def medium_ui # self.medium.presence || 'MEDIUM' # end # def hard_ui # self.hard.presence || 'HARD' # end [:easy, :medium, :hard].each do |field| define_method "#{field}_ui" do [field].presence || field.to_s.upcase end end
  • 28.
    Ruby-world Ecosystem Interpreters:MRI, jRuby, Rubinius, … Frameworks: Ruby on Rails, Sinatra, E, … Editors: Sublime, RubyMine, VIM, … Tests: Rspec, Selenium, Capybara, minitest Servers: Passenger, Unicorn, Puma, Thin, … Libraries (gems): for any tasks … xml, video, image, data processing, API, …. Mobile App: RubyMotion – create native iOS apps in Ruby Community: Google groups, stackoverflow, rubyclub.com.ua, … And more …. Github, BitBucket, CoffeeScript, SASS/SCSS, HAML/SLIM, OAuth, Emails, Ajax, Books(30+), integration with Backbone (and other JS frameworks), payments (PrivatBank has gem), …
  • 29.
    Future • Ruby2.2 is coming • Rails 4.2 is coming + Rails 5 branch is created • Many job offers • New Projects, challenges, startups
  • 30.
    Questions? skype: igorkasyanchuk feel free to contact me 
  • 31.
    Thank you andwelcome to Ruby world