SlideShare a Scribd company logo
1 of 10
@vinothiniBJ
Active Support Improvements
– Rails5
©2014
• https://goo.gl/ZTl8oO
• prev_day
• next_day
• on_weekend
• on_weekday
• next_weekday
• prev_weekday
• prev_week(same_time: true)
• next_week(same_time: true)
Improvements in Date, Time and DateTime
©2014
• days_in_year
class Time
include DateAndTime::Calculations
COMMON_YEAR_DAYS_IN_MONTH = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
class << self
# Returns the number of days in the given month.
# If no year is specified, it will use the current year.
def days_in_month(month, year = current.year)
if month == 2 && ::Date.gregorian_leap?(year)
29
else
COMMON_YEAR_DAYS_IN_MONTH[month]
end
end
# Returns the number of days in the given year.
# If no year is specified, it will use the current year.
def days_in_year(year = current.year)
days_in_month(2, year) + 337
end
end
end
Improvements in Date, Time and DateTime
©2014
• Pluck ( https://goo.gl/yjuBki )
module Enumerable
# Convert an enumerable to an array based on the given key.
#
# [{ name: "David" }, { name: "Rafael" }, { name: "Aaron" }].pluck(:name)
# => ["David", "Rafael", "Aaron"]
#
# [{ id: 1, name: "David" }, { id: 2, name: "Rafael" }].pluck(:id, :name)
# => [[1, "David"], [2, "Rafael"]]
def pluck(*keys)
if keys.many?
map { |element| keys.map { |key| element[key] } }
else
map { |element| element[keys.first] }
end
end
end
©2014
• Without ( https://goo.gl/etJN7h )
class Array
# Returns a copy of the Array without the specified elements.
#
# people = ["David", "Rafael", "Aaron", "Todd"]
# people.without "Aaron", "Todd"
# => ["David", "Rafael"]
#
# Note: This is an optimization of `Enumerable#without` that uses `Array#-`
# instead of `Array#reject` for performance reasons.
def without(*elements)
self - elements
end
end
©2014
• second_to_last (https://goo.gl/Ig0pOY )
• third_to_last
class Array
# Equal to <tt>self[-3]</tt>.
#
# %w( a b c d e ).third_to_last # => "c"
def third_to_last
self[-3]
end
# Equal to <tt>self[-2]</tt>.
#
# %w( a b c d e ).second_to_last # => "d"
def second_to_last
self[-2]
end
end
©2014
• positive? (https://goo.gl/UsTnWl )
• negative?
class Integer
# Returns true if the number is positive.
#
# 1.positive? # => true
# 0.positive? # => false
# -1.positive? # => false
def positive?
self > 0
end
# Returns true if the number is negative.
#
# -1.positive? # => true
# 0.positive? # => false
# 1.positive? # => false
def negative?
self < 0
end
end
©2014
• Inquiry ( https://goo.gl/47bjv7 , https://goo.gl/QpVmU3 )
class ArrayInquirer < Array
def any?(*candidates, &block)
if candidates.none?
super
else
candidates.any? do |candidate|
include?(candidate) || include?(candidate.to_sym)
end
end
end
private
def respond_to_missing?(name, include_private = false)
name[-1] == '?'
end
def method_missing(name, *args)
if name[-1] == '?'
any?(name[0..-2])
else
super
end
end
end
©2014
Q&A ?
Question and Answers
©2014
WE
BUILD
APPS
THAT
PEOPLE
LOVE TO
USE
Enterprise Web Applications
Development
Cross-Platform Business Mobile
Apps Development
Social Media Integrated
Applications Development
Product Development Services

More Related Content

Viewers also liked

Product Catalog
Product CatalogProduct Catalog
Product Catalog
Jack Lee
 
Piano comunale di emergenza Comune di Montignoso
Piano comunale di emergenza Comune di MontignosoPiano comunale di emergenza Comune di Montignoso
Piano comunale di emergenza Comune di Montignoso
Barbara Barsanti
 

Viewers also liked (20)

Diary template
Diary templateDiary template
Diary template
 
Soal konsep geo
Soal konsep geoSoal konsep geo
Soal konsep geo
 
Campus Assessment Solution And Importance
Campus Assessment Solution And Importance   Campus Assessment Solution And Importance
Campus Assessment Solution And Importance
 
Inner Harmony through Mindfulness Meditation by Gustavo Estrada
Inner Harmony through Mindfulness Meditation by Gustavo EstradaInner Harmony through Mindfulness Meditation by Gustavo Estrada
Inner Harmony through Mindfulness Meditation by Gustavo Estrada
 
World Tour Keynote Presentation - London
World Tour Keynote Presentation - LondonWorld Tour Keynote Presentation - London
World Tour Keynote Presentation - London
 
Currrency Trading Tips & News
Currrency Trading Tips & NewsCurrrency Trading Tips & News
Currrency Trading Tips & News
 
During my meditation
During my meditationDuring my meditation
During my meditation
 
M01.JNB.000159_EC 6 Schools Marketing Project Reference
M01.JNB.000159_EC 6 Schools Marketing Project ReferenceM01.JNB.000159_EC 6 Schools Marketing Project Reference
M01.JNB.000159_EC 6 Schools Marketing Project Reference
 
AMN:Addendum
AMN:AddendumAMN:Addendum
AMN:Addendum
 
Product Catalog
Product CatalogProduct Catalog
Product Catalog
 
#Anchor #comedian #Host #CharacterArtist
#Anchor  #comedian #Host #CharacterArtist #Anchor  #comedian #Host #CharacterArtist
#Anchor #comedian #Host #CharacterArtist
 
Return Path World Tour Keynote - San Francisco
Return Path World Tour Keynote - San FranciscoReturn Path World Tour Keynote - San Francisco
Return Path World Tour Keynote - San Francisco
 
Kelas x perkenalan ilmu geografi
Kelas x perkenalan ilmu geografiKelas x perkenalan ilmu geografi
Kelas x perkenalan ilmu geografi
 
Construyendo la web semantica
Construyendo la web semanticaConstruyendo la web semantica
Construyendo la web semantica
 
Cloud computing disadvantages
Cloud computing disadvantagesCloud computing disadvantages
Cloud computing disadvantages
 
1 dicembre 2015 Certaldo
1 dicembre 2015 Certaldo 1 dicembre 2015 Certaldo
1 dicembre 2015 Certaldo
 
Scrivere di Protezione Civile
Scrivere di Protezione CivileScrivere di Protezione Civile
Scrivere di Protezione Civile
 
Piano comunale di emergenza Comune di Montignoso
Piano comunale di emergenza Comune di MontignosoPiano comunale di emergenza Comune di Montignoso
Piano comunale di emergenza Comune di Montignoso
 
Hiv
HivHiv
Hiv
 
Boosting Skilling Performance - Solutions for Training Institutes Skill India
Boosting Skilling Performance - Solutions for Training Institutes Skill IndiaBoosting Skilling Performance - Solutions for Training Institutes Skill India
Boosting Skilling Performance - Solutions for Training Institutes Skill India
 

Similar to Active Support Improvements in Rails 5

C programming & data structure [arrays & pointers]
C programming & data structure   [arrays & pointers]C programming & data structure   [arrays & pointers]
C programming & data structure [arrays & pointers]
MomenMostafa
 
A3 sec -_regular_expressions
A3 sec -_regular_expressionsA3 sec -_regular_expressions
A3 sec -_regular_expressions
a3sec
 
Google: Drive, Documents and Apps Script - How to work efficiently and happily
Google:  Drive, Documents  and Apps Script - How to work efficiently and happilyGoogle:  Drive, Documents  and Apps Script - How to work efficiently and happily
Google: Drive, Documents and Apps Script - How to work efficiently and happily
Alessandra Santi
 
Football graph - Neo4j and the Premier League
Football graph - Neo4j and the Premier LeagueFootball graph - Neo4j and the Premier League
Football graph - Neo4j and the Premier League
Mark Needham
 
Building Single-Page Web Appplications in dart - Devoxx France 2013
Building Single-Page Web Appplications in dart - Devoxx France 2013Building Single-Page Web Appplications in dart - Devoxx France 2013
Building Single-Page Web Appplications in dart - Devoxx France 2013
yohanbeschi
 

Similar to Active Support Improvements in Rails 5 (20)

Ranges calendar-novosibirsk-2015-08
Ranges calendar-novosibirsk-2015-08Ranges calendar-novosibirsk-2015-08
Ranges calendar-novosibirsk-2015-08
 
FluentMigrator - Dayton .NET - July 2023
FluentMigrator - Dayton .NET - July 2023FluentMigrator - Dayton .NET - July 2023
FluentMigrator - Dayton .NET - July 2023
 
The machine learning process: From ideation to deployment with Azure Machine ...
The machine learning process: From ideation to deployment with Azure Machine ...The machine learning process: From ideation to deployment with Azure Machine ...
The machine learning process: From ideation to deployment with Azure Machine ...
 
C programming & data structure [arrays & pointers]
C programming & data structure   [arrays & pointers]C programming & data structure   [arrays & pointers]
C programming & data structure [arrays & pointers]
 
Rethinking metrics: metrics 2.0 @ Lisa 2014
Rethinking metrics: metrics 2.0 @ Lisa 2014Rethinking metrics: metrics 2.0 @ Lisa 2014
Rethinking metrics: metrics 2.0 @ Lisa 2014
 
A3 sec -_regular_expressions
A3 sec -_regular_expressionsA3 sec -_regular_expressions
A3 sec -_regular_expressions
 
TSQL Functions (SQL Server)
TSQL Functions (SQL Server)TSQL Functions (SQL Server)
TSQL Functions (SQL Server)
 
Google: Drive, Documents and Apps Script - How to work efficiently and happily
Google:  Drive, Documents  and Apps Script - How to work efficiently and happilyGoogle:  Drive, Documents  and Apps Script - How to work efficiently and happily
Google: Drive, Documents and Apps Script - How to work efficiently and happily
 
Python lecture 05
Python lecture 05Python lecture 05
Python lecture 05
 
Architecture for scalable Angular applications
Architecture for scalable Angular applicationsArchitecture for scalable Angular applications
Architecture for scalable Angular applications
 
Sets in python
Sets in pythonSets in python
Sets in python
 
Very basic functional design patterns
Very basic functional design patternsVery basic functional design patterns
Very basic functional design patterns
 
Mapping Online Publics (Part 2)
Mapping Online Publics (Part 2)Mapping Online Publics (Part 2)
Mapping Online Publics (Part 2)
 
Football graph - Neo4j and the Premier League
Football graph - Neo4j and the Premier LeagueFootball graph - Neo4j and the Premier League
Football graph - Neo4j and the Premier League
 
Method::Signatures
Method::SignaturesMethod::Signatures
Method::Signatures
 
Building Single-Page Web Appplications in dart - Devoxx France 2013
Building Single-Page Web Appplications in dart - Devoxx France 2013Building Single-Page Web Appplications in dart - Devoxx France 2013
Building Single-Page Web Appplications in dart - Devoxx France 2013
 
Effective Application State Management (@DevCamp2017)
Effective Application State Management (@DevCamp2017)Effective Application State Management (@DevCamp2017)
Effective Application State Management (@DevCamp2017)
 
How to not blow up spaceships
How to not blow up spaceshipsHow to not blow up spaceships
How to not blow up spaceships
 
Digital analytics with R - Sydney Users of R Forum - May 2015
Digital analytics with R - Sydney Users of R Forum - May 2015Digital analytics with R - Sydney Users of R Forum - May 2015
Digital analytics with R - Sydney Users of R Forum - May 2015
 
The Future of Sharding
The Future of ShardingThe Future of Sharding
The Future of Sharding
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Active Support Improvements in Rails 5

  • 2. ©2014 • https://goo.gl/ZTl8oO • prev_day • next_day • on_weekend • on_weekday • next_weekday • prev_weekday • prev_week(same_time: true) • next_week(same_time: true) Improvements in Date, Time and DateTime
  • 3. ©2014 • days_in_year class Time include DateAndTime::Calculations COMMON_YEAR_DAYS_IN_MONTH = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] class << self # Returns the number of days in the given month. # If no year is specified, it will use the current year. def days_in_month(month, year = current.year) if month == 2 && ::Date.gregorian_leap?(year) 29 else COMMON_YEAR_DAYS_IN_MONTH[month] end end # Returns the number of days in the given year. # If no year is specified, it will use the current year. def days_in_year(year = current.year) days_in_month(2, year) + 337 end end end Improvements in Date, Time and DateTime
  • 4. ©2014 • Pluck ( https://goo.gl/yjuBki ) module Enumerable # Convert an enumerable to an array based on the given key. # # [{ name: "David" }, { name: "Rafael" }, { name: "Aaron" }].pluck(:name) # => ["David", "Rafael", "Aaron"] # # [{ id: 1, name: "David" }, { id: 2, name: "Rafael" }].pluck(:id, :name) # => [[1, "David"], [2, "Rafael"]] def pluck(*keys) if keys.many? map { |element| keys.map { |key| element[key] } } else map { |element| element[keys.first] } end end end
  • 5. ©2014 • Without ( https://goo.gl/etJN7h ) class Array # Returns a copy of the Array without the specified elements. # # people = ["David", "Rafael", "Aaron", "Todd"] # people.without "Aaron", "Todd" # => ["David", "Rafael"] # # Note: This is an optimization of `Enumerable#without` that uses `Array#-` # instead of `Array#reject` for performance reasons. def without(*elements) self - elements end end
  • 6. ©2014 • second_to_last (https://goo.gl/Ig0pOY ) • third_to_last class Array # Equal to <tt>self[-3]</tt>. # # %w( a b c d e ).third_to_last # => "c" def third_to_last self[-3] end # Equal to <tt>self[-2]</tt>. # # %w( a b c d e ).second_to_last # => "d" def second_to_last self[-2] end end
  • 7. ©2014 • positive? (https://goo.gl/UsTnWl ) • negative? class Integer # Returns true if the number is positive. # # 1.positive? # => true # 0.positive? # => false # -1.positive? # => false def positive? self > 0 end # Returns true if the number is negative. # # -1.positive? # => true # 0.positive? # => false # 1.positive? # => false def negative? self < 0 end end
  • 8. ©2014 • Inquiry ( https://goo.gl/47bjv7 , https://goo.gl/QpVmU3 ) class ArrayInquirer < Array def any?(*candidates, &block) if candidates.none? super else candidates.any? do |candidate| include?(candidate) || include?(candidate.to_sym) end end end private def respond_to_missing?(name, include_private = false) name[-1] == '?' end def method_missing(name, *args) if name[-1] == '?' any?(name[0..-2]) else super end end end
  • 10. ©2014 WE BUILD APPS THAT PEOPLE LOVE TO USE Enterprise Web Applications Development Cross-Platform Business Mobile Apps Development Social Media Integrated Applications Development Product Development Services