0

I am working on a remote server with Putty. My class looks like:

class Hangman
  def initialize
    puts "Hello world"
  end
end

But when I write in Putty ruby hangman.rb, it skips to the next editor console line without showing anything. Any suggestions?

2
  • 3
    You need to actually do something; you're just defining a class. Commented Feb 13, 2014 at 15:49
  • 1
    Add Hangman.new at the end to see your message. Or in irb type load "hangman.rb" then you can try out your new class interactively Commented Feb 13, 2014 at 15:50

2 Answers 2

2
class Hangman
  def initialize
    puts "Hello world"
   end
end

hangman = Hangman.new

So you forgot to crate an instance of the object you defined. Everytime you call .new method on your object, you get a new instance of it and code inside def initialize is ran.

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

1 Comment

added, but still nothing. My file is called hangman.rb and the class is called Hangman. Ideas?
1

You define the class (with the constructor) but you don't use it. Create an object:

Hangman.new

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.