1

I wrote a basic ruby program with TextMate in Mac OS:

def hello
  puts " This works!"
end

name it Check-it.rb

I open a Terminal session, cd to the directory where the program is stored.

Then I type

ruby Check-it.rb

And nothing appears.

ruby -v

shows me the version, so it's there. But with this and every other Ruby program, nothing appears.

2
  • 3
    You’ve defined a method, but your program never calls it. Commented Feb 14, 2021 at 3:06
  • Nice minimal verifiable example! Commented Feb 16, 2021 at 18:02

2 Answers 2

1

As others already pointed out. The code in your file

def hello
  puts " This works!"
end

defines a method called hello that outputs a string. But that method is never called. To actually call that method and run it change your code in the file to

def hello                          # this block defines the `hello` method
  puts " This works!"
end

hello                              # this line calls the method `hello`
Sign up to request clarification or add additional context in comments.

2 Comments

Okay, I feel like the dumbest developer in the world. That was the answer. Thank you!
@RobertGavila I've been programming for 50 years now. Everybody has "smack yourself on the forehead!" moments, it goes with the territory. My own forehead is quite flat at this point.
0

I think you are not calling this method at all. Call this method and then run your code, it will work.

3 Comments

Thank you Zain. I get the prize for the dumbest developer in the world.
If this answer your issue, then kindly consider accepting my answer :)
Hi, Zain. I clicked on the checkmark, if that helps. Thank you.

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.