class is converting fixnum to array!?!

S

Stuart Brand

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
 
R

Robert Klemme

Stuart said:
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
 
S

Stuart Brand

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 => "(e-mail address removed)",: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 = "(e-mail address removed)"

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

Carlos

Stuart said:
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.
--
 
S

Stuart Brand

Carlos said:
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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top