0

I have a file 'page.rb' containing:

require_relative "template.rb" class MM8 < Template end 

I then have a file 'template.rb' containing:

class Template end 

Why can't I extend the MM8 class with the Template class? I get 'uninitialized constant Template (NameError)' when I try to run the program.

1
  • what exactly is require_relative doing? Is it the equivalent of writing more code on a page, or is it starting a new ruby process, etc. Commented Apr 6, 2015 at 10:17

1 Answer 1

4

Try to call require_relative without file extension:

require_relative 'template' 

You can read more about the difference between require and require_relative here.

Sign up to request clarification or add additional context in comments.

2 Comments

@ZachSmith Are you sure that template.rb and page.rb are in the same folder? Because i've just tested your code and it works fine.
Ah they were, but it is working now. I hadn't saved template.rb with the actual class defined :p. Sorry, thanks for the help

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.