Uninitialized constant VoiceSynth (NameError)

Hello,
I’m trying to access singleton class from different file and above error
occurs.

============== vsynth.rb

require ‘win32ole’
require ‘singleton’

class VoiceSynth
include Singleton

attr_accessor :sapi

def initialize
@sapi = WIN32OLE.new(‘SAPI.SpVoice’)
end

def say text
@sapi.Speak text
end
end

=============== main.rb

require ‘./vsynth’

VoiceSynth.instance.say “Hellooooo”

=============== end

Everything looks fine for me, especially as I have already used other
singleton class in this project and it worked.
What could be wrong?

Cheers,
Alex

Have you tried using require_relative ‘vsynth’? require ‘./vsynth’
depends on the directory the script was called from.

– Matma R.

W dniu 2012-09-19 21:44, Bartosz Dziewoński pisze:

Have you tried using require_relative ‘vsynth’? require ‘./vsynth’
depends on the directory the script was called from.

– Matma R.

None of these work.
vsync.rb is in the same folder as main.rb
I have included other files this way and they work, everything looks
perfectly fine.

When I call

 VoiceSynth.instance.say "hello"

after the class in vsynth.rb and run only this file, it works.

Alex

W dniu 2012-09-20 02:05, 7stud – pisze:

How many files named vsynth.rb do you have in the current directory?

Only one.

How many files named vsynth.rb do you have in the current directory?

Try creating these two files in the same directory:

#my_classes.rb:

require ‘singleton’

class Dog
include Singleton

def bark
puts ‘hi’
end
end

=====

#my_prog.rb

require ‘./my_classes’

Dog.instance.bark

Then try running my_prog.rb with the prompt pointing to the directory
containing those two files. If you get that to work, change the name of
your file from vsynth.rb to my_vsynth.rb and then change the require to:

require ‘./my_vsynth’