views:

458

answers:

5

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?

+1  A: 

I know the question was talking about Ruby, but I think you meant rails (which is what it was tagged as). Rails is a web framework that uses the ruby programming language.

install rubyonrails.

Type:

rails projectname
cd projectname
ruby script/server

Navigate to http://localhost:3000

Brian R. Bondy
Ok thanx but i am on shared hosting and it tells me that I can interpret ruby. I have check 'activate rybyonrails'. What's then?
toddoon
You need to check with your hosting provider.
ScArcher2
A: 
puts "Hello, World!"

To run Ruby scripts on the web, you need to use a special server, run through (F)CGI, or do some other stuff; there are several ways to get different languages HTTP-accessible. However, the simplest way is probably to use a Ruby web framework, such as Ruby on Rails or Merb -- these projects include servers and all of the things you need to get going.

cookiecaper
+4  A: 

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.

ScArcher2
it isn't interpreted see my web page http://ruby.bg-36.com/helloworld.rb
toddoon
I'm afraid you'd better have a look at the suggested Ruby On Rails tutorials before...
Manrico Corazzi
@toddoon Those are command line hello world programs written in ruby. It looks like you are more interested in ruby as a web programming language. Rails is the tool you need to be looking at. I linked a guide in my answer.
ScArcher2
I have this error nowApplication errorRails application failed to start properly"
toddoon
How do i execute command in terminal like ruby script/generate because I have no ssh console?
toddoon
use cmd.exe or powershell.exe.
JasonTrue
Or, if you like, you could install cygwin and use bash. If you prefer a gui, you could alternatively use something like the Aptana IDE rails mode.
JasonTrue
+1  A: 

You can take a look at this Ruby Programming Wiki on Wikibooks

There is also a getting started for Rails

Code

puts 'Hello world'

Run

$ ruby hello-world.rb
Hello world
thijs
A: 

Just copy and past this code on your terminal. Then click enter.

ruby -e "puts 'Hello world'"
Zeck