Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a ruby Hello world?

I know in PHP you have to intrepret a page like index.php, but in Ruby how does it work? I don't know what is the Ruby extension like index.php for PHP. Could you help me?

like image 675
toddoon Avatar asked Apr 01 '09 14:04

toddoon


People also ask

How do you write Hello World in Ruby?

Writing Code rb that you created, you need to write a single line of code that prints the string Hello World! to your terminal. To print in Ruby, you need to use the method puts which is short for "out*put s*tring." And because Hello World! is a string, you need to surround your text with "" . puts "Hello World!"


1 Answers

If you are talking about a command line program this will work.

puts "Hello World" 

or if you want an object oriented version

class HelloWorld    def initialize(name)       @name = name.capitalize    end    def sayHi       puts "Hello #{@name}!"    end end  hello = HelloWorld.new("World") hello.sayHi 

If you are looking for a ruby on rails version of Hello World. Check the Getting Started Guide for Rails.

like image 197
ScArcher2 Avatar answered Oct 06 '22 09:10

ScArcher2