# Return class as Integer

**URL:** <https://www.ruby-forum.com/t/return-class-as-integer/181831>\
**Category:** Ruby\
**Created:** [January 18, 2010, 11:03pm UTC](https://www.ruby-forum.com/t/return-class-as-integer/181831 "2010-01-18T23:03:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![atheeq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3be4f8/32.png) [@atheeq](https://www.ruby-forum.com/u/atheeq)\
**Post date:** [January 18, 2010, 11:03pm UTC](https://www.ruby-forum.com/t/return-class-as-integer/181831/1 "2010-01-18T23:03:48Z")

</div>

hello,

Can anyone tell me how to get a return class as Integer in ruby?

and to use Integer.new method with parameter as a number…

---

<div class="post-metadata">

**Author:** ![atheeq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3be4f8/32.png) [@atheeq](https://www.ruby-forum.com/u/atheeq)\
**Post date:** [January 18, 2010, 11:41pm UTC](https://www.ruby-forum.com/t/return-class-as-integer/181831/2 "2010-01-18T23:41:18Z")

</div>

On Jan 18, 2010, at 5:03 PM, Atheeq P. wrote:

> hello,
> 
> Can anyone tell me how to get a return class as Integer in ruby?
> 
> and to use Integer.new method with parameter as a number.

Integer is an abstract class is Ruby. You want a Fixnum  
(32 bit integers) or a Bignum (arbitrarily large integers).

Fixnum and Bignum are subclasses of Integer. Just use regular  
decimal notation to ‘generate’ fixnums and bignums instances.

> > 42.class  
> > =\> Fixnum
> 
> > 4200000000.class  
> > =\> Bignum

Gary W.

---

<div class="post-metadata">

**Author:** ![atheeq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3be4f8/32.png) [@atheeq](https://www.ruby-forum.com/u/atheeq)\
**Post date:** [January 19, 2010, 4:42am UTC](https://www.ruby-forum.com/t/return-class-as-integer/181831/3 "2010-01-19T04:42:10Z")

</div>

On Jan 18, 2010, at 7:17 PM, Rob B. wrote:

> No, but they’re close enough. There’s a few bits used to identify some immediate values in the MRI implementation. On a 64-bit platform, a Fixnum will be used up to (1 \<\< 62 - 1). The difference tends to matter only when you’re trying to do true 32-bit (or 64-bit) things like cryptographic algorithms where bit shifts or bit rotations are defined on an exact word size.

Yep. Thanks for expanding on my post. I just didn’t feel like all those  
details were going to be helpful in the context of the original  
question.

Gary W.

---

<div class="post-metadata">

**Author:** ![atheeq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3be4f8/32.png) [@atheeq](https://www.ruby-forum.com/u/atheeq)\
**Post date:** [January 19, 2010, 1:17am UTC](https://www.ruby-forum.com/t/return-class-as-integer/181831/4 "2010-01-19T01:17:17Z")

</div>

On Jan 18, 2010, at 7:05 PM, lalawawa wrote:

> > decimal notation to ‘generate’ fixnums and bignums instances.  
> > irb(main):009:0\> (1 \<\< 29).class  
> > =\> Fixnum  
> > irb(main):010:0\>
> 
> This is on Ubuntu Linux.

No, but they’re close enough. There’s a few bits used to identify some  
immediate values in the MRI implementation. On a 64-bit platform, a  
Fixnum will be used up to (1 \<\< 62 - 1). The difference tends to  
matter only when you’re trying to do true 32-bit (or 64-bit) things  
like cryptographic algorithms where bit shifts or bit rotations are  
defined on an exact word size.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![atheeq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3be4f8/32.png) [@atheeq](https://www.ruby-forum.com/u/atheeq)\
**Post date:** [January 19, 2010, 1:06am UTC](https://www.ruby-forum.com/t/return-class-as-integer/181831/5 "2010-01-19T01:06:08Z")

</div>

Gary W. wrote:

> Gary W.  
> I don’t think Fixnums are 32 bit.

irb(main):008:0\> (1 \<\< 30).class  
=\> Bignum  
irb(main):009:0\> (1 \<\< 29).class  
=\> Fixnum  
irb(main):010:0\>

This is on Ubuntu Linux.
