Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date class different in Ruby stdlib and Rails stdlib

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?


2 Answers

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.

like image 71
Ryan Bigg Avatar answered Sep 15 '26 10:09

Ryan Bigg


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}
like image 42
webmat Avatar answered Sep 15 '26 11:09

webmat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!