### Home Classes Methods

### In Files

- lib/active_support/core_ext/integer/inflections.rb
- lib/active_support/core_ext/integer/time.rb
- lib/active_support/core_ext/integer/multiple.rb

### Parent

Object

### Methods

- #month
- #months
- #multiple_of?
- #ordinalize
- #year
- #years

### Class/Module Index

Quicksearch

- ActiveSupport
- ActiveSupport::Autoload
- ActiveSupport::BacktraceCleaner
- ActiveSupport::Base64
- ActiveSupport::BasicObject
- ActiveSupport::Benchmarkable
- ActiveSupport::BufferedLogger
- ActiveSupport::BufferedLogger::Severity
- ActiveSupport::Cache
- ActiveSupport::Cache::Entry
- ActiveSupport::Cache::FileStore
- ActiveSupport::Cache::MemCacheStore
- ActiveSupport::Cache::MemoryStore
- ActiveSupport::Cache::NullStore
- ActiveSupport::Cache::Store
- ActiveSupport::Cache::Strategy
- ActiveSupport::Cache::Strategy::LocalCache
- ActiveSupport::Cache::Strategy::LocalCache::LocalStore
- ActiveSupport::Callbacks
- ActiveSupport::Callbacks::ClassMethods
- ActiveSupport::Concern
- ActiveSupport::Configurable
- ActiveSupport::Configurable::ClassMethods
- ActiveSupport::Configurable::Configuration
- ActiveSupport::Dependencies
- ActiveSupport::Dependencies::ClassCache
- ActiveSupport::Dependencies::WatchStack
- ActiveSupport::Deprecation
- ActiveSupport::DescendantsTracker
- ActiveSupport::Duration
- ActiveSupport::FileUpdateChecker
- ActiveSupport::FileWatcher
- ActiveSupport::FileWatcher::Backend
- ActiveSupport::Gzip
- ActiveSupport::Gzip::Stream
- ActiveSupport::HashWithIndifferentAccess
- ActiveSupport::HashWithIndifferentAccess
- ActiveSupport::Inflector
- ActiveSupport::Inflector::Inflections
- ActiveSupport::InheritableOptions
- ActiveSupport::JSON
- ActiveSupport::JSON::Encoding
- ActiveSupport::JSON::Encoding::CircularReferenceError
- ActiveSupport::JSON::Encoding::Encoder
- ActiveSupport::JSON::Variable
- ActiveSupport::LogSubscriber
- ActiveSupport::LogSubscriber::TestHelper
- ActiveSupport::LogSubscriber::TestHelper::MockLogger
- ActiveSupport::Memoizable
- ActiveSupport::Memoizable::InstanceMethods
- ActiveSupport::MessageEncryptor
- ActiveSupport::MessageEncryptor::InvalidMessage
- ActiveSupport::MessageVerifier
- ActiveSupport::MessageVerifier::InvalidSignature
- ActiveSupport::Multibyte
- ActiveSupport::Multibyte::Chars
- ActiveSupport::Multibyte::EncodingError
- ActiveSupport::Multibyte::Unicode
- ActiveSupport::Multibyte::Unicode::Codepoint
- ActiveSupport::Multibyte::Unicode::UnicodeDatabase
- ActiveSupport::Notifications
- ActiveSupport::Notifications::Event
- ActiveSupport::Notifications::Fanout
- ActiveSupport::Notifications::Instrumenter
- ActiveSupport::OrderedHash
- ActiveSupport::OrderedOptions
- ActiveSupport::Railtie
- ActiveSupport::Rescuable
- ActiveSupport::Rescuable::ClassMethods
- ActiveSupport::SafeBuffer
- ActiveSupport::SafeBuffer::SafeConcatError
- ActiveSupport::StringInquirer
- ActiveSupport::TaggedLogging
- ActiveSupport::TestCase
- ActiveSupport::Testing
- ActiveSupport::Testing::Assertions
- ActiveSupport::Testing::Declarative
- ActiveSupport::Testing::Isolation
- ActiveSupport::Testing::Isolation::Forking
- ActiveSupport::Testing::Isolation::MiniTest
- ActiveSupport::Testing::Isolation::Subprocess
- ActiveSupport::Testing::Isolation::TestUnit
- ActiveSupport::Testing::Pending
- ActiveSupport::Testing::Performance
- ActiveSupport::Testing::Performance::Benchmarker
- ActiveSupport::Testing::Performance::ForClassicTestUnit
- ActiveSupport::Testing::Performance::ForMiniTest
- ActiveSupport::Testing::Performance::Metrics
- ActiveSupport::Testing::Performance::Metrics::Amount
- ActiveSupport::Testing::Performance::Metrics::Base
- ActiveSupport::Testing::Performance::Metrics::CpuTime
- ActiveSupport::Testing::Performance::Metrics::DigitalInformationUnit
- ActiveSupport::Testing::Performance::Metrics::GcRuns
- ActiveSupport::Testing::Performance::Metrics::GcTime
- ActiveSupport::Testing::Performance::Metrics::Memory
- ActiveSupport::Testing::Performance::Metrics::Objects
- ActiveSupport::Testing::Performance::Metrics::ProcessTime
- ActiveSupport::Testing::Performance::Metrics::Time
- ActiveSupport::Testing::Performance::Metrics::UserTime
- ActiveSupport::Testing::Performance::Metrics::WallTime
- ActiveSupport::Testing::Performance::Performer
- ActiveSupport::Testing::Performance::Profiler
- ActiveSupport::Testing::ProxyTestResult
- ActiveSupport::Testing::RemoteError
- ActiveSupport::Testing::SetupAndTeardown
- ActiveSupport::Testing::SetupAndTeardown::ClassMethods
- ActiveSupport::Testing::SetupAndTeardown::ForClassicTestUnit
- ActiveSupport::Testing::SetupAndTeardown::ForMiniTest
- ActiveSupport::TimeWithZone
- ActiveSupport::TimeZone
- ActiveSupport::XmlMini
- ActiveSupport::XmlMini_LibXMLSAX
- ActiveSupport::XmlMini_LibXMLSAX::HashBuilder
- ActiveSupport::XmlMini_NokogiriSAX
- ActiveSupport::XmlMini_NokogiriSAX::HashBuilder
- Test
- Test::Unit
- Test::Unit::Collector
- Test::Unit::Collector::ObjectSpace
- Object
- Object::HashWithIndifferentAccess
- Object::MissingSourceFile
- ERB
- ERB::Util
- I18n
- I18n::Railtie
- LoadError
- LoadError
- Logger
- Logger::SimpleFormatter
- Array
- Base64
- Benchmark
- BigDecimal
- Class
- Date
- DateTime
- Enumerable
- FalseClass
- File
- Float
- Hash
- Integer
- Kernel
- Module
- NameError
- NilClass
- Numeric
- Process
- QualifiedConstUtils
- Range
- Regexp
- String
- Symbol
- Time
- TrueClass
- URI

No matching classes.

# Integer

### Public Instance Methods

month() click to toggle source
Alias for: months
months() click to toggle source

Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years.

These methods use Time#advance for precise date calculations when using from_now, ago, etc. as well as adding or subtracting their results from a Time object. For example:

    # equivalent to Time.now.advance(:months => 1)
    1.month.from_now

    # equivalent to Time.now.advance(:years => 2)
    2.years.from_now

    # equivalent to Time.now.advance(:months => 4, :years => 5)
    (4.months + 5.years).from_now

While these methods provide precise calculation when used as in the examples above, care should be taken to note that this is not true if the result of `months’, `years’, etc is converted before use:

    # equivalent to 30.days.to_i.from_now
    1.month.to_i.from_now

    # equivalent to 365.25.days.to_f.from_now
    1.year.to_f.from_now

In such cases, Ruby’s core Date and Time should be used for precision date and time arithmetic

    # File lib/active_support/core_ext/integer/time.rb, line 30
    def months
      ActiveSupport::Duration.new(self * 30.days, [[:months, self]])
    end

Also aliased as: month
multiple_of?(number) click to toggle source

Check whether the integer is evenly divisible by the argument.

    0.multiple_of?(0)  #=> true
    6.multiple_of?(5)  #=> false
    10.multiple_of?(2) #=> true

    # File lib/active_support/core_ext/integer/multiple.rb, line 7
    def multiple_of?(number)
      number != 0 ? self % number == 0 : zero?
    end

ordinalize() click to toggle source

Ordinalize turns a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.

    1.ordinalize     # => "1st"
    2.ordinalize     # => "2nd"
    1002.ordinalize  # => "1002nd"
    1003.ordinalize  # => "1003rd"
    -11.ordinalize   # => "-11th"
    -1001.ordinalize # => "-1001st"

    # File lib/active_support/core_ext/integer/inflections.rb, line 14
    def ordinalize
      ActiveSupport::Inflector.ordinalize(self)
    end

year() click to toggle source
Alias for: years
years() click to toggle source

    # File lib/active_support/core_ext/integer/time.rb, line 35
    def years
      ActiveSupport::Duration.new(self * 365.25.days, [[:years, self]])
    end

Also aliased as: year

[Validate]

Generated with the Darkfish Rdoc Generator 2.