For this piece of code:
class myBaseClass   def funcTest()     puts "baseClass"   end end myBaseClass.new.funcTest   I am getting an error:
NameError: undefined local variable or method `myBaseClass' for main:Object from c:/Users/Yurt/Documents/ruby/polymorphismTest.rb:9 from (irb):145:in `eval' from (irb):145 from c:/Ruby192/bin/irb:12:in `<main>' irb(main):152:0> x=myBaseClass.new   When I tryx=myBaseClass.new, I get:
NameError: undefined local variable or method `myBaseClass' for main:Object from (irb):152   Has someone already encountered this problem? I don't think my code can be wrong.
Ruby NameError Uninitialized Constant Causes You'll see this error when the code refers to a class or module that it can't find, often because the code doesn't include require, which instructs the Ruby file to load the class.
What is the difference between a class and a module? Modules are collections of methods and constants. They cannot generate instances. Classes may generate instances (objects), and have per-instance state (instance variables).
In ruby, all constants including class names must begin with a capital letter. myBaseClass would be interpreted as an undefined local variable. MyBaseClass would work properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With