The classical introductory exercise. Just say "Hello, World!".
"Hello, World!" is the traditional first program for beginning programming in a new language or environment.
The objectives are simple:
If everything goes well, you will be ready to fetch your first real exercise.
For installation and learning resources, refer to the Ruby resources page.
For running the tests provided, you will need the Minitest gem. Open a terminal window and run the following command to install minitest:
gem install minitest
If you would like color output, you can require 'minitest/pride'
in
the test file, or note the alternative instruction, below, for running
the test file.
Run the tests from the exercise directory using the following command:
ruby hello_world_test.rb
To include color from the command line:
ruby -r minitest/pride hello_world_test.rb
This is an exercise to introduce users to using Exercism http://en.wikipedia.org/wiki/%22Hello,_world!%22_program
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
begin
gem 'minitest', '>= 5.0.0'
require 'minitest/autorun'
require_relative 'hello_world'
rescue Gem::LoadError => e
puts "\nMissing Dependency:\n#{e.backtrace.first} #{e.message}"
puts 'Minitest 5.0 gem must be installed for the Ruby track.'
rescue LoadError => e
puts "\nError:\n#{e.backtrace.first} #{e.message}"
puts DATA.read
exit 1
end
# Common test data version: 1.1.0 be3ae66
class HelloWorldTest < Minitest::Test
def test_say_hi
# skip
assert_equal "Hello, World!", HelloWorld.hello
end
end
__END__
*****************************************************
You got an error, which is exactly as it should be.
This is the first step in the Test-Driven Development
(TDD) process.
The most important part of the error is
cannot load such file
It's looking for a file named hello_world.rb that doesn't
exist yet.
To fix the error, create an empty file named hello_world.rb
in the same directory as the hello_world_test.rb file.
Then run the test again.
For more guidance as you work on this exercise, see
GETTING_STARTED.md.
*****************************************************
class HelloWorld
def self.hello
"Hello, World!"
end
end
A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.
Here are some questions to help you reflect on this solution and learn the most from it.
Level up your programming skills with 3,449 exercises across 52 languages, and insightful discussion with our volunteer team of welcoming mentors. Exercism is 100% free forever.
Sign up Learn More
Community comments