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; Using Operators To get started using operators in Ruby, follow these steps: Enter this code in a new file, operators....


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
  #11  
Old 10-09-2007, 02:22 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

Using Operators

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

    Quote:
    value = 3
    puts value
    value = value + 3 #addition
    puts value
    value = value / 2 #division
    puts value
    value = value * 3 #multiplication
    puts value
    value = value ** 2 #exponentiation
    puts value
  2. Save operators.rb.
  3. Run operators.rb:
Quote:
C:\rubydev>ruby operators.rb
3
6
3
9
81
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12  
Old 10-09-2007, 02:28 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 Operators

Ruby Operators Operator Description
[ ] Array reference
[ ]= Array element set
** Exponentiation
! Not
~ Complement
+ Unary plus
- Minus
* Multiply
/ Divide
% Modulo
+ Plus
- Minus
>> Right shift
<< Left shift
& Bitwise And
^ Bitwise exclusive Or (Xor)
| Regular Or

Comparison operators:

<= Less than or equal to
< Less than
> Greater than
>= Greater than or equal to

Equality and pattern match operators:

<=> Less than, equal to, greater than
== Equal to
=== Tests equality in a when clause of a case statement
!= Not equal to
=~ Regular expression pattern match
&& Logical And
|| Logical Or
.. Inclusive range
... Exclusive range
? Ternary if
: Else

Assignment

= Normal assign
%= Modulus and assign
/= Divide and assign
-= Subtract and assign
+= Add and assign
*= Multiply and assign
**= Exponent and assign
defined? True if symbol defined
not Logical negation
and Logical composition
or Logical composition

Statement modifiers

if
unless
while
until

begin/end Block expression
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13  
Old 10-12-2007, 03:36 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 Arrays

There are plenty of ways to work with data in Ruby. Next up is to store it in arrays. Arrays act as groups of variables, and you can access each variable in an array with an index number.

For example, to create an array, you use the [] operator like this:

array = [1, 2, 3]

This creates an array with three elements, 1, 2, and 3. You access those elements using an array index like this:

Quote:
puts array[0] #prints 1
puts array[1] #prints 2
puts array[2] #prints 3
Note that the first element in the array corresponds to array index 0, not 1, and the second element is at index 1, the third at index 2, and so on. You can also assign values to arrays, using the array index:

Quote:
array[0] = 4 #assigns 4 to array[0]
array[1] = 5 #assigns 5 to array[1]
array[2] = 6 #assigns 6 to array[2]
puts array[2] #prints 6
As you know, Ruby variables can store text strings as well as numbers, and you can store both in arrays.

Here’s an example:

array = [“Hello”, “there”, “sweetie”, 1, 2, 3]

This creates an array filled with six elements, three of which are text and three of which are numbers:

Quote:
array = [“Hello”, “there”, “sweetie”, 1, 2, 3]
puts array[1] #prints “there”
puts array[4] #prints 2
__________________
Prasanna Vignesh
MCPD | Web Developer
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14  
Old 09-11-2008, 12:16 AM
Miakoda Miakoda is offline
D-Web Trainee
 
Join Date: Jul 2008
Posts: 36
Miakoda is on a distinguished road
Default Re: Ruby on Rails

Hi


Nice Prasanna. You doin a good job. It is so helpful for me. I know the HTML and now i want to upgrade my self, so i thinking about the ROR or PHP.
I think ROR has nice future. so i looking for the ROR.

thanks
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 11:43 PM.


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