How to use Active Support core extensions How to use Active Support core extensions ruby ruby

How to use Active Support core extensions


Since using Rails should handle this automatically I'm going to assume you're trying to add Active Support to a non-Rails script.

Read "How to Load Core Extensions".

Active Support's methods got broken into smaller groups in Rails 3, so we don't end up loading a lot of unneeded stuff with a simple require 'activesupport'. Now we have to do things like

require 'active_support/core_ext/object/blank'

If you don't care about granularity, you can choose to load bigger chunks. If you want everything in one big gulp use...

For 1.9.2:

rvm 1.9.2irb -firb(main):001:0> require 'active_support/all'=> trueirb(main):002:0> 1.week.ago=> 2010-11-14 17:56:16 -0700irb(main):003:0> 

For 1.8.7:

rvm 1.8.7irb -firb(main):001:0> require 'rubygems'=> trueirb(main):002:0> require 'active_support/all'=> trueirb(main):003:0> 1.week.ago=> Sun Nov 14 17:54:19 -0700 2010irb(main):004:0> 


You can granularly add libraries via the already mentioned

require 'active_support/core_ext/some_class/some_file'

There is also another level up where you can

require 'active_support/core_ext/some_class'

But, at the moment, this is unfortunately not available for Time, Date and DateTime.

A way around this is to require 'active_support/time' which will give you Time, Date and DateTime which would solve the OP was asking for without requiring everything.


My Rails patch, which adds active_support/core_ext/date and date_time, made it into Rails v4.0.0, so now you can require these individually. YAY!


In my case the following link worked:

https://bundler.io/blog/2019/01/04/an-update-on-the-bundler-2-release.html

$ cat Gemfile.lock | grep -A 1 "BUNDLED WITH"BUNDLED WITH   1.17.3$ gem install bundler -v '1.17.3'