Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Modules Ruby Core Modules Enumerable

Travis Eubanks
Travis Eubanks
12,566 Points

When to include modules

So If im not working on any framework like Rails and im just simply trying to build a program in ruby... do I have to 'include <Module name>' for every module I want to use for intance like Math and Enumerable? OR is there like a standard library I can INCLUDE that stores all the "standard" libraries kind of like rails does

2 Answers

Raymond Sapida
Raymond Sapida
33,049 Points

Hi there,

Ruby has a lot of the basic libraries that most people use. If you're building a program with just Ruby, all the core objects are included but you have to include modules like Enumerable and Comparable.

Outside of that, if you wanted to use methods available in Rails, you could add Rails Active Support which extends some of the Ruby classes. You could add the whole thing or pick which parts you wanted to include for your program. It's the closest thing I know to a Ruby standard library that isn't already included in Ruby.

Travis Eubanks
Travis Eubanks
12,566 Points

Great thank you Raymond appreciate the insight!

Hi guys,

This is the second time the Active Support extension / gem has been mentioned on the forum. The first time was here (which also mentions ActiveRecord) :

https://teamtreehouse.com/forum/time-columns-should-be-decimal-right

My question/comment:

Is there going to be a Ruby course with a deep dive into Active Support coming up eventually in the roadmap?


Some links:

Article: Some Ways ActiveSupport Helps Ruby Developers:

http://www.sitepoint.com/ways-activesupport-helps-ruby-developers/

Instrumenting Your Code With ActiveSupport Notifications:

http://technology.customink.com/blog/2013/12/19/instrumenting-your-code-with-activesupport-notifications/

Some old articles / tutorials on ActiveSupport::Callbacks

http://thomasmango.com/2011/09/02/getting-to-know-active-support-callbacks/

http://www.intridea.com/blog/2012/3/22/define-custom-callbacks-for-activerecord-and-more


Active Support Github:

https://github.com/rails/rails/tree/master/activesupport/lib/active_support/core_ext

--by the way, according to this stackoverflow thread, ActiveSupport "ActiveSupport is more separate now in Rails 3":

http://stackoverflow.com/questions/3053119/use-rails-3s-activesupport-core-extensions-outside-rails

Raymond Sapida
Raymond Sapida
33,049 Points

It would be really great if there was a course on it here. Most of what I know about Active Support is from the Ruby on Rails guide on it. And thank you, for the links you added. They were very helpful to me since I've been trying to find more resources on how to use active support effectively. It just feels like there so much included in that module that it's difficult to decide where to begin.