[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

class is converting fixnum to array!?!

Stuart Brand

8/1/2006 10:50:00 AM

Hi all

I have made a class to return a value of either 1 or 0 depending on
conditions, however once it returns the fixnum is converted to an Array?

user = 0

puts user.class # -> fixnum
user = My_class.test(name)
puts user.class # -> Array


class My_class

self.test(name)
if name == name then
return 1
else
return 0
end

end

end

this is an example and not the true code, the principle is there, the
basics are that when a value is returned it converts user to an
Array?????


Thanks all

Stuart

--
Posted via http://www.ruby-....

4 Answers

Robert Klemme

8/1/2006 11:54:00 AM

0

Stuart Brand wrote:
> Hi all
>
> I have made a class to return a value of either 1 or 0 depending on
> conditions, however once it returns the fixnum is converted to an Array?
>
> user = 0
>
> puts user.class # -> fixnum
> user = My_class.test(name)
> puts user.class # -> Array
>
>
> class My_class
>
> self.test(name)
> if name == name then
> return 1
> else
> return 0
> end
>
> end
>
> end
>
> this is an example and not the true code, the principle is there, the
> basics are that when a value is returned it converts user to an
> Array?????

That's exactly the reason why we cannot possibly help you here. The
code above clearly does not return an array. Try using "p" to print out
the result of calling "test" to get an idea what goes wrong.

Kind regards

robert

Stuart Brand

8/1/2006 12:03:00 PM

0

this is the full class and code to call it, it out puts fixnum then
array

class Ldap

def self.auth(name)

ldap= Net::LDAP.new :host => '172.16.1.1', :port => 389, :auth =>
{:method => :simple,:username => "ldapquery@example.com",:password =>
"password"}
filter = Net::LDAP::Filter.eq( "samaccountname", "#{name}" )
treebase = "ou=accounts,dc=example,dc=com"

ldap.search( :base => treebase, :filter => filter ) do |entry|

if "#{entry["samaccountname"]}" == "#{name}" then
return 1
else
return 0
end

end

end
end


address = "user@example.com"

username = "#{address}".sub(/@.*/, '')
puts user.class
user = Ldap.auth(username)
puts user.class


--
Posted via http://www.ruby-....

Carlos

8/1/2006 12:13:00 PM

0

Stuart Brand wrote:

> this is the full class and code to call it, it out puts fixnum then
> array
[...]
> ldap.search( :base => treebase, :filter => filter ) do |entry|
>
> if "#{entry["samaccountname"]}" == "#{name}" then
> return 1
> else
> return 0
> end
>
> end

What if you never enter that block, because ldap.search never found
anything?

Then the result of ldap.search will be returned, probably an empty array.
--



Stuart Brand

8/1/2006 12:25:00 PM

0

Carlos wrote:

>
> What if you never enter that block, because ldap.search never found
> anything?
>
> Then the result of ldap.search will be returned, probably an empty
> array.

Thats it, thanks very much :)

--
Posted via http://www.ruby-....