Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7741801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:07:17+00:00 2026-06-01T09:07:17+00:00

I have the simple following code, which is working in a ruby (not rails)

  • 0

I have the simple following code, which is working in a ruby (not rails) app:

require 'gmail'

Gmail.new('my_account', 'my_password') do |gmail|
end

I am able to get a connection to the Gmail account and do some stuff in there.

However, I want to use this Gem in a Rails app, and therefore I have tried adding the following into the Gemfile:

gem "ruby-gmail",         "0.2.1"
gem "mime",               "0.1"

However, when I try to use this in a rake task, like this:

task :scrap_receipts_gmail => :environment do
  Gmail.new('my_account', 'my_password') do |gmail|
    puts gmail.inspect
  end
end

I get the following error:

uninitialized constant Object::Gmail

This is solved if I add require 'gmail'. My question is:

Why would I have to require gmail, if I have already specified that in the Gemfile?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:07:18+00:00Added an answer on June 1, 2026 at 9:07 am

    The module/class namespace has to match the directory structure. For example, in lib/foo/bar.rb, if and only if the namespace is Foo::Bar can it be auto loaded by Rails, otherwise you have to require it explicitly.

    In this case, Gmail is defined as a class, which doesn’t match the directory structure. If Gmail was defined as a module (namespace ::Gmail matchs directory structure), then you’ll never need to explicitly require "gmail".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple application with the following code: FileInfo[] files = (new DirectoryInfo(initialDirectory)).GetFiles();
I have the following simple javascript code, which handles the Return Key, I don't
I have the following sample code which doesn't seem to want to run. import
i have the following simple code, but it doesn,t work <ul> <li id=one onmouseover=this.style.background-color='white';>
I have the following simple code abstract class A { public abstract void Test(Int32
I have a simple 3D cube that I can rotate using the following code:
I have a simple controller test, containing a.o. the following code: context POST :create
I have the following simple Java code: package testj; import java.util.*; public class Query<T>
I have the following code (correct for my simple tests) for a linked list
I have used following code to create a simple PDF file. It executes fine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.