1. Create a new Ruby Application named SimpleRuby
2. Type the following code in Main.rb and hit return.
class Greeter
3. Show how the "end" was generated for the class
| Explanation Point: Now we need to add a couple of methods |
4. Type the following method into the Greeter class
def initialize(inName)
5. Hit return. Inside the method type the following code.
@name = inName.
6. Show the code completion and choose the "capitalize" method.
7. Show the help documentation for the capitalize method.
8. Add this method as well to the Greeter class.
def salute
9. Add the following code to the salute method.
puts "Hello #
10. Show code completion on the # .
11. Inside the #{} type @n and let the code completion choose "@name Greeter". Make sure to add the following ".
12. After the Greeter class, add the following code.
g = Greeter.new("david")
g.salute()
13. Run the Ruby application and show the output.
14. Set a breakpoint on the following line.
puts "Hello #{@name}"
15. Debug the Ruby Application and show how the program stops on the line.
16. Switch to the "Local Variables" window and show the "@name" variable.
17. At the top of the file (before the class definition) type jc<Tab> to expand the require 'java' template. Complete the code as follows:
require 'java' include_class 'com.sun.speech.freetts.Voice' include_class 'com.sun.speech.freetts.VoiceManager'
18. Comment out the following line in the salute method.
puts "Hello #{@name}"
19. Put the following code below the commented out line.
# Get a voice
voice = VoiceManager.getInstance.getVoice('kevin16')
# Allocate a resource for the voice
voice.allocate
voice.speak(@name)
20. Run the Ruby Application with the volume turned up.