# Using a module within another module

**URL:** <https://www.ruby-forum.com/t/using-a-module-within-another-module/108851>\
**Category:** Rails\
**Created:** [July 8, 2007, 3:16am UTC](https://www.ruby-forum.com/t/using-a-module-within-another-module/108851 "2007-07-08T03:16:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![juan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a698b9/32.png) [@juan](https://www.ruby-forum.com/u/juan)\
**Post date:** [July 8, 2007, 3:16am UTC](https://www.ruby-forum.com/t/using-a-module-within-another-module/108851/1 "2007-07-08T03:16:42Z")

</div>

Hi,

I’m trying to use the module  
ActiveSupport::CoreExtensions::Time::Calculations in a helper module,  
but I get a nasty error. My module looks like this:

require ‘rubygems’  
gem ‘activesupport’

include ActiveSupport::CoreExtensions::Time::Calculations

module CalendarHelper

# code…

days = self.class.days\_in\_month(month, year)

# more code…

But every time I invoke it, I get the following error:

#\<NameError: cannot remove Object::ClassMethods\>  
["/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:422:in  
`remove_const'", "/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:422:in`remove\_constant’",  
“/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:273:in  
`remove_unloadable_constants!'", "/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:273:in`remove\_unloadable\_constants!’”,  
“/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:72:in  
`clear'", "/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:60:in`reset\_application!’”,  
“/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:116:in  
`reset_after_dispatch'", "/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:51:in`dispatch’”,  
“/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick\_server.rb:113:in  
`handle_dispatch'", "/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:79:in`service’”, “/usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in  
`service'", "/usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in`run’”,  
“/usr/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'", "/usr/local/lib/ruby/1.8/webrick/server.rb:162:in`start\_thread’”,  
“/usr/local/lib/ruby/1.8/webrick/server.rb:95:in `start'", "/usr/local/lib/ruby/1.8/webrick/server.rb:92:in`start’”,  
“/usr/local/lib/ruby/1.8/webrick/server.rb:23:in `start'", "/usr/local/lib/ruby/1.8/webrick/server.rb:82:in`start’”,  
“/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick\_server.rb:63:in  
`dispatch'", "/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/webrick.rb:59", "/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in`require’”,  
“/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:495:in  
`require'", "/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in`new\_constants\_in’”,  
“/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:495:in  
`require'", "/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39", "/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in`require’”, “script/server:3”]

Do you know what’s going on ? It’s a bit hard to be a newbie in this RnR  
world (now I understand how people new to Java feel like…)

Thanks in advance,  
Juan

---

<div class="post-metadata">

**Author:** ![juan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a698b9/32.png) [@juan](https://www.ruby-forum.com/u/juan)\
**Post date:** [July 8, 2007, 11:29pm UTC](https://www.ruby-forum.com/t/using-a-module-within-another-module/108851/2 "2007-07-08T23:29:27Z")

</div>

hi there Juan,

I can’t quite see what you’re trying to do.  
The lovely module you’re looking at is already included in Time.

So, if you want to do that,  
just do Time.days\_in\_month(4, 2004)

gives you the number of days in april 2004

def days(cal)  
Time.days\_in\_month(cal.month, cal.year)  
end

also,  
maybe the original error was because your include should have been  
inside the module.

Juan MedÃ­n wrote:

> Hi,
> 
> I’m trying to use the module  
> ActiveSupport::CoreExtensions::Time::Calculations in a helper module,  
> but I get a nasty error. My module looks like this:

days = self.class.days\_in\_month(month, year)

---

<div class="post-metadata">

**Author:** ![juan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a698b9/32.png) [@juan](https://www.ruby-forum.com/u/juan)\
**Post date:** [July 9, 2007, 11:14pm UTC](https://www.ruby-forum.com/t/using-a-module-within-another-module/108851/3 "2007-07-09T23:14:55Z")

</div>

Juan Medín wrote:

> Hi,
> 
> I’m trying to use the module  
> ActiveSupport::CoreExtensions::Time::Calculations in a helper module,  
> but I get a nasty error. My module looks like this:
> 
> require ‘rubygems’  
> gem ‘activesupport’

This leaves activesupport unloaded.

The (now) prefered usage is:

require “rubygems”  
require “activesupport” # picks up latest version of activesupport

or

require “rubgems”  
gem “activesupport”, someversion # defines which version to load  
require “activesupport”

Granted, the message “require\_gem is obsolete, use gem instead” is  
misleading.

Just wanted to note this - I cannot help with your original message.

Stefan
