Date class different in Ruby stdlib and Rails stdlib

By : Sanjay
Source: Stackoverflow.com
Question!

I want to use the Date::ABBR_MONTHS constant in my rails application. I see the Ruby stdlib documentation at http://www.ruby-doc.org/stdlib/ which does not seem to have this constant. However, this constant is there at http://stdlib.rubyonrails.org/

What is the difference between these two libraries?

This constant is working on my unix deployment machine but not on my dev machine on windows. Can anybody explain whats going on?

By : Sanjay


Answers

ABBR_MONTHS is added to Date by ActiveSupport.

Rails is in fact a set of a few gems. ActiveSupport's role is mostly to add niceties to the Ruby language and other agnostic tools like the Inflector and the 2.days way of creating Time instances and so on.

So if you need this kind of capability outside of your rails app for some reason, you're in luck:

require 'rubygems' #If not already done
require 'activesupport'
puts Date::Format::ABBR_MONTHS.inspect
#=> {"oct"=>10, "jul"=>7, "jan"=>1, "dec"=>12, "jun"=>6, "apr"=>4, "feb"=>2, "may"=>5, "sep"=>9, "aug"=>8, "mar"=>3, "nov"=>11}
By : webmat


ABBR_MONTHS is something you get given to you by ActiveSupport and it's just added into the Date class. The first library is for ruby, where the second one is for ruby on rails. The constant may not be working because of different versions of Rails.

By : Ryan Bigg


This video can help you solving your question :)
By: admin