1 Replies - 1607 Views - Last Post: 16 October 2008 - 06:40 AM Rate Topic: -----

#1 jobema   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 01-October 08

ruby method

Post icon  Posted 16 October 2008 - 06:27 AM

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?

Is This A Good Question/Topic? 0
  • +

Replies To: ruby method

#2 MitkOK   User is offline

  • D.I.C Regular
  • member icon

Reputation: 32
  • View blog
  • Posts: 403
  • Joined: 09-August 07

Re: ruby method

Posted 16 October 2008 - 06:40 AM

Like this ?
puts inputmethod.uniq.size

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1