Ruby on Rails development from scratch (Windows) (34)-Active Support

Source: Internet
Author: User
Tags ruby on rails

Active support is a set of libraries provided with rails, active support extends some of the classes in Ruby, and this time we'll look at some of the most common features.

1. Extension of the number type

The Fixnum class adds two methods: even and odd?

The scaling method is also added:

Puts 20.bytes #=> 20

Puts 20.kilobytes #=> 20480

Puts 20.megabytes #=> 20971520

Puts 20.gigabytes #=> 21474836480

Puts 20.terabytes #=> 21990232555520

There is also a time based scaling that converts accepted values to corresponding seconds, the month () and year () methods get approximate values, and the month is assumed to be 30 days, and is assumed to be 365 days.

Puts 20.minutes #=> 1200

Puts 20.hours #=> 72000

Puts 20.days #=> 1728000

Puts 20.weeks #=> 12096000

Puts 20.fortnights #=> 24192000

Puts 20.months #=> 51840000

Puts 20.years #=> 630720000

2. Expansion of time

The time class adds some methods to help us with the computation

now = Time.now

Puts now

Puts Now.ago (3600)

Puts Now.at_beginning_of_day

Puts Now.at_beginning_of_month

Puts Now.at_beginning_of_week

Puts Now.at_beginning_of_year

Puts Now.at_midnight

Puts Now.change (: Hour => 13)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.