-1

Here a screen of my code and error messages I get

Code and error message

Uninitialized constant CLASS (NameError)

I am using Cloud9, Ruby, Rails server. I created two simple test scripts. test.rb and parent.rb

parent.rb has a method 'yes' which displays the word yes... test is trying to be a child/dependant of parent so that it can access parent's method 'yes'. But no luck.

I've tried "class test < parent" I've tried adding "require 'parent'" I've tried changing parent from class parent to module parent.

ddb
  • 2,423
  • 7
  • 28
  • 38
TSteff
  • 31
  • 2
  • http://stackoverflow.com/questions/3672586/what-is-the-difference-between-require-relative-and-require-in-ruby – Casper Nov 09 '16 at 09:36

1 Answers1

0

you need to use require_relative to make it work

Also, yes method in Parent class is an instance method and you need to instantiate Parent class in order to user it's instance method.

Your test.rb should look like this:

require_relative 'parent.rb'

class Test < Parent
  Parent.new.yes
end
sa77
  • 3,563
  • 3
  • 24
  • 37