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-forum.com/ .
Hello !
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
There are few things missing in you code, as is, it doesn’t run. It tried to modify it, and then I get the expected results (not the ones you point out).
Could you please provide us with a minimum working example ?
Cheers !
Vince
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
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-forum.com/ .
Carlos
(Carlos)
1 August 2006 12:12
5
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.
···
--
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-forum.com/\ .