IT Community - Software Programming, Web Development and Technical Support

Ruby Datastructure

This is a discussion on Ruby Datastructure within the Ruby forums, part of the Web Development category; Hi, Can any one explain about Ruby Datastructure?...


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

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 03-27-2008, 09:41 PM
bluesky bluesky is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 201
bluesky is on a distinguished road
Default Ruby Datastructure

Hi,
Can any one explain about Ruby Datastructure?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-27-2008, 09:43 PM
nnraja nnraja is offline
D-Web Programmer
 
Join Date: May 2007
Posts: 94
nnraja is on a distinguished road
Default Re: Ruby Datastructure

Data structures is a generalized name for arrays,hashes,string
Data structures have been invented because simple variables are not enough for solving more complex problems.
Methods are give other names too, such as functions,subprograms or procedures, while in other programming languages there might be several differences between all these, they all mean pretty much the same thing in Ruby, although everyone is trying to using the term "method" only.

Here's how you define a method:

def mymethod
puts "this is my first method"
end
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-27-2008, 09:46 PM
shaalini shaalini is offline
D-Web Analyst
 
Join Date: Apr 2007
Posts: 342
shaalini is on a distinguished road
Default Re: Ruby Datastructure

call a method (when you call a method Ruby executes the statements in the method):

by giving it's name:

mymethod
pass arguments to a method

def showme(message)
puts message
end

message="ruby says hello"
showme(message)
__________________
Shaalini.S
Be the Best of Whatever you are...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-27-2008, 09:47 PM
satheesh satheesh is offline
D-Web Programmer
 
Join Date: Aug 2007
Posts: 95
satheesh is on a distinguished road
Default Re: Ruby Datastructure

You can also use like this
def showme(firstw,secondw)
puts firstw + " " + secondw + "!"
end

showme "Thank","you"
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-27-2008, 09:48 PM
satheesh satheesh is offline
D-Web Programmer
 
Join Date: Aug 2007
Posts: 95
satheesh is on a distinguished road
Default Re: Ruby Datastructure

pass a variable number of arguments
def showme(firstw, *therest)
puts firstw + " " + therest.join(" ")
end

showme "Thank", "you", "very", "much!"
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-27-2008, 09:51 PM
shaalini shaalini is offline
D-Web Analyst
 
Join Date: Apr 2007
Posts: 342
shaalini is on a distinguished road
Default Re: Ruby Datastructure

Using methods for returning values

def multi(first,second)
first * second
end

multi(2,536)
__________________
Shaalini.S
Be the Best of Whatever you are...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-27-2008, 09:52 PM
shaalini shaalini is offline
D-Web Analyst
 
Join Date: Apr 2007
Posts: 342
shaalini is on a distinguished road
Default Re: Ruby Datastructure

Return multiple values with a method

def showme()
return “Thank”, “you”
end

array = showme
puts array.join(“ “)

showme

if you want the text to be displayed with spaces between words, assign an array to the method and use the join method on the array.
__________________
Shaalini.S
Be the Best of Whatever you are...
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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What Is RUBY? theseokit Ruby 11 10-11-2008 02:37 AM
Is Ruby for Web? S.Vinothkumar Ruby 6 11-20-2007 01:25 AM
Ruby within .NET? econwriter5 Ruby 0 03-07-2007 05:02 PM
Ruby IDE drecko Ruby 0 02-16-2007 12:11 AM


All times are GMT -7. The time now is 12:02 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0