why ruby?
DESCRIPTION
my story how I started learning and using Ruby by Ihor Kosyanchuk, Technical Leader, SoftServeTRANSCRIPT
![Page 1: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/1.jpg)
{Why Ruby?
my story how I started learning and using Ruby
![Page 2: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/2.jpg)
Plan1. About me2. Why Ruby?3. What is Ruby?4. Ruby on Rails5. Ruby-world Ecosystem6. Future7. Questions
![Page 3: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/3.jpg)
About me
Igor Kasyanchuk
Education: National University of Oil and Gas, PZ-01-1Worked at: Eleks, SoftServe, freelancing, own projectsCompleted projects: 20+Used: Java, Visual C++, C++ BuilderUsing: Ruby, Ruby on Rails, HTML/CSS/JS/etcWorking now: in SoftServe as Ruby, Ruby on Rails Team/Tech Lead
![Page 4: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/4.jpg)
Why Ruby?
I was tired of …
... and many other things
![Page 5: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/5.jpg)
Why Ruby?
And I met Ruby …
say = "I love Ruby"puts say
say['love'] = "*love*"puts say.upcase
5.times { puts say }
![Page 6: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/6.jpg)
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?
![Page 7: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/7.jpg)
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
![Page 8: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/8.jpg)
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
![Page 9: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/9.jpg)
Also, Ruby ishttp://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)); }}
![Page 10: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/10.jpg)
Syntax1. Overview2. Loops3. Blocks4. Classes, Mixins5. OOP in Ruby6. “Dynamicity”
![Page 11: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/11.jpg)
Overviewputs "Hello World"
"LOREM".downcase
"lorem".length
"abcd".split("")if /1999/.match(s) puts "party!"end
t = Time.now
Time.now.strftime("%Y-%m-%d %H:%M:%S")
a = [1, 2, 3, 4]
a[-1](1..1_000_000).each do |i| …end
role = :admin
ROLES = [‘admin’, ‘user’]
x = 1000
user = user.new unless user
![Page 12: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/12.jpg)
Loopsi=0while i < 3 print i, " while\n” i += 1end
for ss in 0..2 print ss, " for doubledot\n”end
array=['zero', 'one', 'two', 'three', 'four', 'five']array.each{|ss| print ss, " array.each\n"}
array[0,3].each{|ss| print ss, " array_first_three.each\n”}
![Page 13: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/13.jpg)
Blocksdef 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!
![Page 14: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/14.jpg)
Classes, Mixinsclass Greeter def initialize(name) @name = name.capitalize end
def salute puts "Hello #{@name}!" endend
# Create a new objectg = Greeter.new("world")
# Output "Hello World!"g.salute
# Creating mixinmodule Log def log(message) puts message endend
# Creating classclass User include Logend
user = User.newuser.log “hello user”
![Page 15: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/15.jpg)
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 eend
![Page 16: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/16.jpg)
“Dynamicity”class Greeter def initialize(name) @name = name end
def method_missing(e) greeting = e.to_s.capitalize "#{greeting} #{@name}" endend
g = Greeter.new("Igor")puts g.hello
=> Hello Igor
1. Strong reflection2. eval3. method_missing4. send5. overload, override anything6. modify, remove, add methods on the fly
![Page 17: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/17.jpg)
Ruby on RailsRuby 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
![Page 18: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/18.jpg)
Ruby on Rails1. Built on Ruby2. Web Application Framework3. Blog in 15 minutes4. MVC, CoC, DRY
![Page 19: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/19.jpg)
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
![Page 20: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/20.jpg)
Web Application Framework
• HTML/HAML/SLIM…• CSS/SCSS/SASS…• JS/CoffeeScript….• MySQL/Postgres/Mongo….• REST/API• Testing• Java, C, Resque, Sphinx, ElasticSearch, etc
![Page 21: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/21.jpg)
Blog in 15 minutes
Check it!
![Page 22: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/22.jpg)
Blog in 15 minutes
Check it!
![Page 23: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/23.jpg)
MVC• Object Relation Mapping• Database Agnostic• CRUD simple• Class to Table, Row to Object
class User < ActiveRecord::Base has_many :photosend
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
![Page 24: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/24.jpg)
MVCConnecting view and model
сlass UsersController < ApplicationController def index @users= User.all end
end
![Page 25: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/25.jpg)
MVCGenerating HTML (using SLIM)
table - @users.each do |user| tr td= user.first_name td= user.last_name
![Page 26: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/26.jpg)
CoCConvention over Configuration
![Page 27: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/27.jpg)
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
![Page 28: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/28.jpg)
Ruby-world EcosystemInterpreters: MRI, jRuby, Rubinius, …Frameworks: Ruby on Rails, Sinatra, E, … Editors: Sublime, RubyMine, VIM, …Tests: Rspec, Selenium, Capybara, minitestServers: Passenger, Unicorn, Puma, Thin, …Libraries (gems): for any tasks … xml, video, image, data processing, API, ….Mobile App: RubyMotion – create native iOS apps in RubyCommunity: 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), …
![Page 29: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/29.jpg)
Future• Ruby 2.2 is coming• Rails 4.2 is coming + Rails 5 branch is created• Many job offers• New Projects, challenges, startups
![Page 30: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/30.jpg)
Questions?
skype: igorkasyanchuk
feel free to contact me
![Page 31: Why Ruby?](https://reader033.vdocuments.site/reader033/viewer/2022061201/547983c6b4af9fb2748b4764/html5/thumbnails/31.jpg)
Thank you
and welcome to Ruby world