Returning argument as a number problem
- From: Haze Noc <h4z3@xxxxxxxxxxxx>
- Date: Tue, 14 Aug 2007 01:47:19 +0900
Hey guys, I have a method as such:
def random(len)
if len !~ /\d+/
pub_send "Invalid number"
elsif len > 30
pub_send "No more then 30 chars"
else
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
random = ""
1.upto(len) { |i| newpass << chars[rand(chars.length)] }
pub_send random
end
end
and i call the method like so..
random($1) if $msg =~ /^rand (\d+)/
the value of $1 will always be a number, but it seems when i am passing
it to the function it returns an error saying it cannot compare len to
30 because the value of len is a string... Any ideas?
Thanks in advance
--
Posted via http://www.ruby-forum.com/.
.
- Follow-Ups:
- Re: Returning argument as a number problem
- From: Sebastian Hungerecker
- Re: Returning argument as a number problem
- From: Stefano Crocco
- Re: Returning argument as a number problem
- Prev by Date: Re: Prototype (the real thing from Ara) problem.
- Next by Date: Re: Prototype (the real thing from Ara) problem.
- Previous by thread: Re: Prototype (the real thing from Ara) problem.
- Next by thread: Re: Returning argument as a number problem
- Index(es):
Relevant Pages
|