edelpero
edelpero

Reputation: 157

My class is calling a non-existing class?

I'm using:

This is my code:

class Report::ExpectedHour

  def initialize(user, options = {})
    @user       = user
    @date_start = options[:start]
    @date_end   = options[:end]
  end

  def expected_hours_range
    previous    = ExpectedHour.previous_dates(@user, @date_start).first
    hours_range = ExpectedHour.between_dates(@user, @date_start, @date_end)

    unless hours_range.include?(previous)
      hours_range << previous
    end

    hours_range
  end

end

Every time I call expected_hours_range from my instance I get this error:

NameError: uninitialized constant Report::ExpectedHour::ExpectedHour
from /home/edelpero/.rvm/gems/ruby-1.9.2-p180@titi/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing_from_s3_library'
from /opt/lampp/htdocs/titi/app/models/report/expected_hour.rb:10:in `expected_hours_range'

I'm not sure why Report::ExpectedHour::ExpectedHour is called because I'm calling ExpectedHour which is an actual existing ActiveRecord class. Also Report::ExpectedHour::ExpectedHour doesn't exist.

Upvotes: 1

Views: 55

Answers (1)

ichigolas
ichigolas

Reputation: 7735

When calling classes inside your class methods, ruby expects it to be either a class nested inside you class itself or a constant. Try this:

class MyClass
  def some_method
    use_external_class = ::ExternalClass::CONSTANTB.bla
    # Use the '::'
  end
end

Upvotes: 2

Related Questions