SlideShare a Scribd company logo
1 of 46
Download to read offline
RUBY 2.0
Pripovjedač: Nikola Šantić
RUBY 2.0
MISIJA U MOSKVI
Pripovjedač: Nikola Šantić
Ruby je programski jezik
Nijedan jezik nije LOŠ
osim Visual Basica
Nijedan jezik nije LOŠ
osim Visual Basica
i PHPa
Nijedan jezik nije LOŠ
osim Visual Basica
i PHPa
i javascripta
Postoje LOŠI jezici
Ali Ruby je odličan
Stvarno
11 razloga zašto je odličan
if (sequel == 7)
print("yes!")
end
series.push("Mission to Moscow")
title.reverse().capitalize()
1. Zagrade!
if sequel == 7
print "yes!"
end
series.push "Mission to Moscow"
title.reverse.capitalize
2. if-ovi bez granica
if character == "Harris"
print "MAHONEY!!!"
end
print "MAHONEY!!!" if character == "Harris"
unless character.russian?
play_academy_theme
end
3. Sve je objekt
"police academy".upcase
=> "POLICE ACADEMY"
3. Sve je objekt
"police academy".upcase
=> "POLICE ACADEMY"
mission_to_moscow = Movie.new
=> #<Movie:0x00000106f95a40>
3. SVE je objekt
"police academy".upcase
=> "POLICE ACADEMY"
19.years.ago
=> Sat, 18 Jun 1994 00:55:38 UTC +00:00
mission_to_moscow = Movie.new
=> #<Movie:0x00000106f95a40>
4. Najljepši literali
'Ovo je string bez posebnih znakova n/'
"Ovo je policijska akademija #{ 6 + 1 }"
/police academy [0-9]+/i
oscar_reception_date = nil
us_gross = 126_247
%w(Lassard Jones Tackleberry) == ["Lassard","Jones","Tackleberry"]
{de: "Mission in Moskau", it: "Missione a Mosca",
hu: "A rendõrakadémia Moszkvában" }
5. Enumeratori
(1..20).each do |i|
puts i
end
5. Enumeratori
(1..20).select{|i| i.even?}
(1..20).each do |i|
puts i
end
5. Enumeratori
(1..20).select{|i| i.even?}.map{|i| "Razbojnik #{i}"}
(1..20).each do |i|
puts i
end
5. Enumeratori
(1..20).select{|i| i.even?}.map{|i| "Razbojnik #{i}"}.each do |i|
puts i
end
(1..20).each do |i|
puts i
end
6. Zamjena dvije varijable
nikad nije bila tako laka
x, y = y, x
7. Duck typing
if mission_to_moscow.respond_to?(:remake)
mission_to_moscow.remake
end
8. DINAMO!
"Tackleberry".methods
=> [:==, :===, :eql?, :hash, :casecmp, :+, :*,
:%, :[], :[]=, ...
8. Dinamično programiranje
"Tackleberry".methods
=> [:==, :===, :eql?, :hash, :casecmp, :+, :*,
:%, :[], :[]=, ...
8. Dinamično programiranje
"Tackleberry".methods
=> [:==, :===, :eql?, :hash, :casecmp, :+, :*,
:%, :[], :[]=, ...
class Character
def speak
# bla bla
end
end
jones = Character.new
jones.speak
8. Dinamično programiranje
"Tackleberry".methods
=> [:==, :===, :eql?, :hash, :casecmp, :+, :*,
:%, :[], :[]=, ...
class Character
def speak
# bla bla
end
end
jones = Character.new
jones.speak
def jones.make_noises
puts "beep! boop!"
end
jones.make_noises
9. Random nasljeđivanje
class RandomSubclass < [Array, Hash, String, Fixnum, Float].sample
end
10. method_missing
class RussianAcademyProxy
def initialize(academy)
@academy = academy
end
def do_russian_stuff
# ...
end
def method_missing(method, *args, &block)
@academy.send(method, *args, &block)
end
end
11. Najlakše brisanje diska
IKAD
require 'fileutils'
FileUtils.rm_rf('/')
Navodno trebam pričati o
Rubyju 2.0
• Dec 1996 - 1.0
• Aug 2003 - 1.8
• Dec 2007 - 1.9.0
• Aug 2010 - 1.9.2
Povijest
FEB 24th 2013 - 2.0
Nije strašno.
Potpuno je kompatibilno s 1.9
Koliko je strašno?
Što je novo?
# encoding: utf-8 više ne treba!
proctooooor = "(╯°□°)╯"
Default UTF-8
Keyword arguments
wrap("Blue Oyster Bar")
=> "***Blue Oyster Bar***"
wrap("Blue Oyster Bar", before: "8=", after: "=>")
=> "8=Blue Oyster Bar=>"
Keyword arguments
Dosad:
wrap("Blue Oyster Bar")
=> "***Blue Oyster Bar***"
wrap("Blue Oyster Bar", before: "8=", after: "=>")
=> "8=Blue Oyster Bar=>"
def wrap(string, options={})
before = options[:before] || '***'
after = options[:after] || '***'
"#{before}#{string}#{after}"
end
Keyword arguments
Odsad:
wrap("Blue Oyster Bar")
=> "***Blue Oyster Bar***"
wrap("Blue Oyster Bar", before: "8=", after: "=>")
=> "8=Blue Oyster Bar=>"
def wrap(string, before: '***', after: '***')
"#{before}#{string}#{after}"
end
Module#prepend
class Character
def speak
puts "Hello"
end
include RussianCulture
end
russian = Character.new
russian.drink_votka
russian.speak
=> "Hello"
Character.ancestors
=> [Character, RussianCulture, Object, Kernel, BasicObject]
module RussianCulture
def drink_votka
end
def speak
puts "привет"
end
end
Module#prepend
class Character
def speak
puts "Hello"
end
prepend RussianCulture
end
russian = Character.new
russian.drink_votka
russian.speak
=> "привет"
Character.ancestors
=> [RussianCulture, Character, Object, Kernel, BasicObject]
module RussianCulture
def drink_votka
end
def speak
puts "привет"
end
end
Module#prepend
module RussianCulture
def speak
puts "привет"
super
puts "прощание"
end
end
russian.speak
=> "привет hello прощание"
class String
def russian?
match(/"p{Cyrillic}+.*?.?"/ui) ? true : false
end
end
"привет".russian? #=> true
Refinements
module RussianQuery
refine String do
def russian?
match(/"p{Cyrillic}+.*?.?"/ui) ? true : false
end
end
end
"привет".respond_to?(:russian?) #=> false
using RussianQuery
"привет".russian? #=> true
Refinements
(1..Float::INFINITY).map{|i|
i.to_s}.select{|s| s =~ /3/}.first(10)
Lazy enumerator
X_X
(1..Float::INFINITY).lazy.map{|i|
i.to_s}.select{|s| s =~ /3/}.first(10)
Lazy enumerator
• %i{first second third} == [:first, :second, :third]
• to_h
• array.bsearch{|x| x >= 4}
• __dir__
• Bolji GC
I još
RVM: rvm get head && rvm install 2.0.0
Kako? Gdje?
rbenv: rbenv install 2.0.0-p0
Hvala!

More Related Content

Viewers also liked (6)

Advanced sass
Advanced sassAdvanced sass
Advanced sass
 
Sass Why for the CSS Guy
Sass Why for the CSS GuySass Why for the CSS Guy
Sass Why for the CSS Guy
 
Atlanta Drupal User's Group - April 2015 - Sasstronauts: Advanced Sass Topics
Atlanta Drupal User's Group - April 2015 - Sasstronauts: Advanced Sass TopicsAtlanta Drupal User's Group - April 2015 - Sasstronauts: Advanced Sass Topics
Atlanta Drupal User's Group - April 2015 - Sasstronauts: Advanced Sass Topics
 
Advanced sass/compass
Advanced sass/compassAdvanced sass/compass
Advanced sass/compass
 
Dyslexia or Second Language Learning?
Dyslexia or Second Language Learning?Dyslexia or Second Language Learning?
Dyslexia or Second Language Learning?
 
Breaking Free from Bootstrap: Custom Responsive Grids with Sass Susy
Breaking Free from Bootstrap: Custom Responsive Grids with Sass SusyBreaking Free from Bootstrap: Custom Responsive Grids with Sass Susy
Breaking Free from Bootstrap: Custom Responsive Grids with Sass Susy
 

Similar to Code@Six - Ruby 2.0

Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technology
ppparthpatel123
 
Kon nichi wa_ruby
Kon nichi wa_rubyKon nichi wa_ruby
Kon nichi wa_ruby
Scott Motte
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介
Wen-Tien Chang
 

Similar to Code@Six - Ruby 2.0 (20)

Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technology
 
Ruby and japanese
Ruby and japaneseRuby and japanese
Ruby and japanese
 
Ruby for Java Developers
Ruby for Java DevelopersRuby for Java Developers
Ruby for Java Developers
 
Get your ass to 1.9
Get your ass to 1.9Get your ass to 1.9
Get your ass to 1.9
 
from Ruby to Objective-C
from Ruby to Objective-Cfrom Ruby to Objective-C
from Ruby to Objective-C
 
Minicurso Ruby e Rails
Minicurso Ruby e RailsMinicurso Ruby e Rails
Minicurso Ruby e Rails
 
Kon nichi wa_ruby
Kon nichi wa_rubyKon nichi wa_ruby
Kon nichi wa_ruby
 
Intro to Ruby (and RSpec)
Intro to Ruby (and RSpec)Intro to Ruby (and RSpec)
Intro to Ruby (and RSpec)
 
Ruby seen by a C# developer
Ruby seen by a C# developerRuby seen by a C# developer
Ruby seen by a C# developer
 
Ruby seen from a C# developer
Ruby seen from a C# developerRuby seen from a C# developer
Ruby seen from a C# developer
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
ORUG - Sept 2014 - Lesson When Learning Ruby/Rails
ORUG - Sept 2014 - Lesson When Learning Ruby/RailsORUG - Sept 2014 - Lesson When Learning Ruby/Rails
ORUG - Sept 2014 - Lesson When Learning Ruby/Rails
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1
 
Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介Ruby 程式語言綜覽簡介
Ruby 程式語言綜覽簡介
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Introducing Ruby
Introducing RubyIntroducing Ruby
Introducing Ruby
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
 
Ruby.new @ VilniusRB
Ruby.new @ VilniusRBRuby.new @ VilniusRB
Ruby.new @ VilniusRB
 
Ruby Xml Mapping
Ruby Xml MappingRuby Xml Mapping
Ruby Xml Mapping
 
Crystal: Fundamentos, objetivos y desafios - Cacic 2019
Crystal: Fundamentos, objetivos y desafios - Cacic 2019Crystal: Fundamentos, objetivos y desafios - Cacic 2019
Crystal: Fundamentos, objetivos y desafios - Cacic 2019
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Code@Six - Ruby 2.0