# Class is converting fixnum to array!?!

**URL:** <https://www.ruby-forum.com/t/class-is-converting-fixnum-to-array/100832>\
**Category:** Ruby\
**Created:** [August 1, 2006, 12:50pm UTC](https://www.ruby-forum.com/t/class-is-converting-fixnum-to-array/100832 "2006-08-01T12:50:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stuartbrand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@stuartbrand](https://www.ruby-forum.com/u/stuartbrand)\
**Post date:** [August 1, 2006, 12:50pm UTC](https://www.ruby-forum.com/t/class-is-converting-fixnum-to-array/100832/1 "2006-08-01T12:50:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stuartbrand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@stuartbrand](https://www.ruby-forum.com/u/stuartbrand)\
**Post date:** [August 1, 2006, 1:35pm UTC](https://www.ruby-forum.com/t/class-is-converting-fixnum-to-array/100832/2 "2006-08-01T13:35:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stuartbrand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@stuartbrand](https://www.ruby-forum.com/u/stuartbrand)\
**Post date:** [August 1, 2006, 1:56pm UTC](https://www.ruby-forum.com/t/class-is-converting-fixnum-to-array/100832/3 "2006-08-01T13:56:03Z")

</div>

Stuart B. wrote:

> 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
```

---

<div class="post-metadata">

**Author:** ![stuartbrand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@stuartbrand](https://www.ruby-forum.com/u/stuartbrand)\
**Post date:** [August 1, 2006, 2:15pm UTC](https://www.ruby-forum.com/t/class-is-converting-fixnum-to-array/100832/4 "2006-08-01T14:15:14Z")

</div>

Stuart B. 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.

---

<div class="post-metadata">

**Author:** ![stuartbrand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@stuartbrand](https://www.ruby-forum.com/u/stuartbrand)\
**Post date:** [August 1, 2006, 2:03pm UTC](https://www.ruby-forum.com/t/class-is-converting-fixnum-to-array/100832/5 "2006-08-01T14:03:09Z")

</div>

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 =\> “removed\_email\_address@domain.invalid”,: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 = “removed\_email\_address@domain.invalid”

username = “#{address}”.sub(/@.\*/, ‘’)  
puts user.class  
user = Ldap.auth(username)  
puts user.class

---

<div class="post-metadata">

**Author:** ![stuartbrand](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@stuartbrand](https://www.ruby-forum.com/u/stuartbrand)\
**Post date:** [August 1, 2006, 2:24pm UTC](https://www.ruby-forum.com/t/class-is-converting-fixnum-to-array/100832/6 "2006-08-01T14:24:30Z")

</div>

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 🙂
