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?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| Hi, Can any one explain about Ruby Datastructure? |
|
#2
| |||
| |||
| 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 |
|
#3
| |||
| |||
| 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... |
|
#4
| |||
| |||
| You can also use like this def showme(firstw,secondw) puts firstw + " " + secondw + "!" end showme "Thank","you" |
|
#5
| |||
| |||
| pass a variable number of arguments def showme(firstw, *therest) puts firstw + " " + therest.join(" ") end showme "Thank", "you", "very", "much!" |
|
#6
| |||
| |||
| Using methods for returning values def multi(first,second) first * second end multi(2,536)
__________________ Shaalini.S ![]() Be the Best of Whatever you are... |
|
#7
| |||
| |||
| 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... |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ruby??? | smith21 | Ruby | 3 | 07-17-2009 08:42 PM |
| What Is RUBY? | theseokit | Ruby | 12 | 10-21-2008 11:07 PM |
| PHP vs Ruby | suman | PHP Programming | 2 | 10-02-2008 12:59 AM |
| Is Ruby for Web? | S.Vinothkumar | Ruby | 6 | 11-20-2007 01:25 AM |
| Ruby IDE | drecko | Ruby | 0 | 02-16-2007 12:11 AM |
Our Partners |