School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,403 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,631 people online right now. Registration is fast and FREE... Join Now!




ruby method

 

ruby method

jobema

16 Oct, 2008 - 05:27 AM
Post #1

New D.I.C Head
*

Joined: 1 Oct, 2008
Posts: 10

I need a Ruby method that takes an array of numbers as an input parameter and returns the count of the number of distinct numbers in the array.
this is what I had but I not sure

def inputmethod
inlist =[] # an empty array
print "Enter a number or just hit 'Enter' to quit"
myin = gets.chomp
while(myin.length>0)
inlist = inlist << myin.to_i
print "Enter a number or just hit 'Enter' to quit"
myin = gets.chomp
end
return inlist
end

could someone help me if I'm right?

User is offlineProfile CardPM
+Quote Post


MitkOK

RE: Ruby Method

16 Oct, 2008 - 05:40 AM
Post #2

D.I.C Regular
Group Icon

Joined: 9 Aug, 2007
Posts: 356



Thanked: 19 times
Dream Kudos: 250
My Contributions
Like this ?
ruby
puts inputmethod.uniq.size

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 10:30PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month