IT Community - Software Programming, Web Development and Technical Support

Ruby on Rails

This is a discussion on Ruby on Rails within the Ruby forums, part of the Web Development category; Installing Ruby and Rails The installation process of Ruby and Rail on Windows, MAC and Linux are discussed detail in ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Ruby

Register FAQ Members List Calendar Mark Forums Read

Reply
 
Thread Tools Display Modes
  #1  
Old 10-09-2007, 01:48 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up Ruby on Rails

Installing Ruby and Rails

The installation process of Ruby and Rail on Windows, MAC and Linux are discussed detail in the following thread.

http://www.discussweb.com/ruby/4012-...s-windows.html

thanks
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 10-09-2007, 01:51 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up Ruby on Rails

Getting Started with Ruby

Ruby is the language that is going to make everything happen. To work with Ruby, you need a text editor of the kind you already used to get the Ruby on Rails example working, such as
word pad (Start➪ Programs➪Accessories➪WordPad) or
Notepad (Start➪Programs➪Accessories➪Notepad) in Windows.

Each Ruby program should be saved with the extension .rb
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 10-09-2007, 01:55 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up Ruby on Rails

Hello World in Ruby

To get started with Ruby and make it display a Hello World message, follow these steps:
  1. Start your text editor and enter the following Ruby code:

    Code:
    puts “Hello World.”
  2. Save the file as hello.rb. Make sure you save the file as a text file (select Text Document in the Save As Type drop-down), and if you are using windows WordPad or Notepad, make sure you enclose the name of the file in quotes—”hello.rb”—before saving to prevent those editors from saving the file as hello.rb.rtf or hello.rb.txt.

  3. Use Ruby to run this new program and see the results. Just enter the ruby command followed by the name of the program at the command line:

C:\rubydev>ruby hello.rb

Hello World.
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 10-09-2007, 01:57 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up Ruby on Rails

Working with Numbers in RUBY

To get started with numbers in Ruby, follow these steps:
  1. Enter this Ruby code in a new file:
    Code:
    puts 12345
    puts 3.1415
    puts 31415.0e-4
    puts 12_345_678_987_654_321
    puts 0xddff
  2. Save the file as numbers.rb.
  3. Use Ruby to run numbers.rb:

Quote:
C:\rubydev>ruby numbers.rb
12345
3.1415
3.1415
12345678987654321
56831
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5  
Old 10-09-2007, 02:00 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up Ruby on Rails

Working with Strings in Ruby

To get started with strings in Ruby, follow these steps:
  1. Enter this Ruby code in a new file, strings.rb:


    Code:
    puts “Hello”
    puts “Hello “ + “there”
    puts ‘Nice to see you.’
    puts %Q/How are you?/
    puts %Q!Fine, and you?!
    puts %q!I’m also fine, thanks.!
    puts “I have to say, ‘I am well.’”
    puts “I’ll also say, \”Things are fine.\””
  2. Save the file as strings.rb.
  3. Run strings.rb using Ruby to see the result:

Quote:
C:\rubydev>ruby strings.rb
Hello
Hello there
Nice to see you.
How are you?
Fine, and you?
I’m also fine, thanks.
I have to say, ‘I am well.’
I’ll also say, “Things are fine.”
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6  
Old 10-09-2007, 02:04 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up Ruby on Rails

Ruby’s reserved words:
  1. __FILE
  2. __ def
  3. in
  4. self
  5. __LINE
  6. __ defined?
  7. module
  8. super
  9. BEGIN
  10. do
  11. next
  12. then
  13. END
  14. else
  15. nil
  16. true
  17. alias
  18. elsif
  19. not
  20. undef
  21. and
  22. end
  23. or
  24. unless
  25. begin
  26. ensure
  27. redo
  28. until
  29. break
  30. false
  31. rescue
  32. when
  33. case
  34. for
  35. retry
  36. while
  37. class
  38. if
  39. return
  40. yield
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7  
Old 10-09-2007, 02:07 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Default Ruby on Rails

Storing Data in Variables - Working with Variables

To get started with variables in Ruby, follow these steps:
  1. Enter this Ruby code in a new file, variables.rb:

    Code:
    temperature = 36
    puts “The temperature is “ + String(temperature) + “.”
    temperature = temperature + 5
    puts “Now the temperature is “ + String(temperature) + “.”
  2. Save the variables.rb file.
  3. Run variables.rb to see the result:
Quote:
C:\rubydev>ruby variables.rb
The temperature is 36.
Now the temperature is 41.
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8  
Old 10-09-2007, 02:14 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up Ruby on Rails

Creating Constants

You can also create constants in Ruby. A constant holds a value that you do not expect to change, such as

the value of pi:

PI = 3.1415926535


IP_SERVER_SOURCE = “903.111.333.055”
IP_SERVER_TARGET = “903.111.333.056”


Unlike other languages, Ruby allows you to change the values in constants by assigning a new value to
them:
CONST = 1
CONST = 2

However, you’ll get a warning each time you do this:

constants.rb:2: warning: already initialized constant CONST
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9  
Old 10-09-2007, 02:16 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up Ruby on Rails

Interpolating Variables


To get started with interpolating expressions in double-quoted strings in Ruby, follow these steps:
  1. Enter this code in a new file, doublequoted.rb:

    Quote:
    temperature = 36
    puts “The temperature is #{temperature}.”
    temperature = temperature + 5
    puts “Now the temperature is #{temperature}.”
  2. Save doublequoted.rb.
  3. Run doublequoted.rb:
Quote:
C:\rubydev>ruby doublequoted.rb
The temperature is 36.
Now the temperature is 41.
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10  
Old 10-09-2007, 02:19 AM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up Ruby on Rails

Reading Text


To get started reading text in Ruby, follow these steps:
  1. Enter this code in a new file, gets.rb:
    Quote:
    print “Please enter the temperature: “
    gets
    chomp
    puts “The temperature is #{$_}.”
  2. Save the file and run it.
  3. Ruby displays the prompt Please enter the temperature: and then waits for a response from you:
    Quote:
    C:\rubydev>ruby gets.rb
    Please enter the temperature:
  4. Enter a temperature and press Enter. Ruby reads the text that you have entered, chomps the
    newline character off the end of it, and displays the resulting text:
Quote:
C:\rubydev>ruby gets.rb
Please enter the temperature: 36
The temperature is 36.
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Installing Ruby and Rails on Windows prasannavigneshr Ruby 3 01-09-2009 04:24 AM
PHP vs Ruby suman PHP Programming 2 10-02-2008 12:59 AM
Ruby on Rails server config vivekanandan Ruby 7 08-04-2007 04:02 AM
setting up ruby on rails in Fedora core 6 rgm5 Ruby 1 04-17-2007 11:42 PM
Ruby IDE drecko Ruby 0 02-16-2007 12:11 AM


All times are GMT -7. The time now is 12:21 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0