# Boolean to text?

**URL:** <https://www.ruby-forum.com/t/boolean-to-text/77035>\
**Category:** Rails\
**Created:** [November 23, 2006, 5:29pm UTC](https://www.ruby-forum.com/t/boolean-to-text/77035 "2006-11-23T17:29:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kurth\_Bemis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cdc98d/32.png) [@Kurth\_Bemis](https://www.ruby-forum.com/u/Kurth_Bemis)\
**Post date:** [November 23, 2006, 5:29pm UTC](https://www.ruby-forum.com/t/boolean-to-text/77035/1 "2006-11-23T17:29:22Z")

</div>

I’m new to RoR, but learning quickly (I hope)

I have stored a boolean value in my database (is\_organic). How do I  
convert the value to something meaningful. In this case 1 = Organic.

I suppose I could do it with a loop, but that seems wasteful. Are  
these functions available in RoR?

~k

---

<div class="post-metadata">

**Author:** ![Kurth\_Bemis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cdc98d/32.png) [@Kurth\_Bemis](https://www.ruby-forum.com/u/Kurth_Bemis)\
**Post date:** [November 23, 2006, 6:21pm UTC](https://www.ruby-forum.com/t/boolean-to-text/77035/2 "2006-11-23T18:21:32Z")

</div>

On Nov 23, 2006, at 5:26 PM, Kurth Bemis wrote:

> I’m new to RoR, but learning quickly (I hope)
> 
> I have stored a boolean value in my database (is\_organic). How do I  
> convert the value to something meaningful. In this case 1 = Organic.
> 
> I suppose I could do it with a loop, but that seems wasteful. Are  
> these functions available in RoR?

You don’t. In the Ruby side you use always Ruby booleans:

thing.is\_organic = true  
thing.toggle! :is\_organic  
thing.is\_organic? # provided by AR if type is boolean

nonorganics = Thing.find\_all\_by\_is\_organic(false)

You see.

– fxn

---

<div class="post-metadata">

**Author:** ![Kurth\_Bemis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cdc98d/32.png) [@Kurth\_Bemis](https://www.ruby-forum.com/u/Kurth_Bemis)\
**Post date:** [November 23, 2006, 6:51pm UTC](https://www.ruby-forum.com/t/boolean-to-text/77035/3 "2006-11-23T18:51:36Z")

</div>

I do see.

Exactly what I was looking for.

Thank You.

On 11/23/06, Xavier N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> – fxn
> 
> >

–

Ozone Computer  
Computer consulting, Services and Sales.  
9 Main Street  
Springfield, Vermont  
1-802-885-8030

---

<div class="post-metadata">

**Author:** ![Kurth\_Bemis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cdc98d/32.png) [@Kurth\_Bemis](https://www.ruby-forum.com/u/Kurth_Bemis)\
**Post date:** [November 24, 2006, 4:18am UTC](https://www.ruby-forum.com/t/boolean-to-text/77035/4 "2006-11-24T04:18:40Z")

</div>

Hi, I would recommend using a Hash to achieve your goal. Also, I  
would highly recommend getting a good understanding of the Ruby  
language an its associated idoms.  
You’ll find this to be very helpful when you’re working with the Rails  
web development framework.

Good luck,

-Conrad

---

<div class="post-metadata">

**Author:** ![Kurth\_Bemis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cdc98d/32.png) [@Kurth\_Bemis](https://www.ruby-forum.com/u/Kurth_Bemis)\
**Post date:** [November 24, 2006, 4:30am UTC](https://www.ruby-forum.com/t/boolean-to-text/77035/5 "2006-11-24T04:30:41Z")

</div>

Conrad T. wrote:

> Hi, I would recommend using a Hash to achieve your goal.

Ooh, I guess that where I said “without creating a new lookup table”, I  
could have extended that to “and not a Hash”. Same idiom different  
framework.

---

<div class="post-metadata">

**Author:** ![Kurth\_Bemis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cdc98d/32.png) [@Kurth\_Bemis](https://www.ruby-forum.com/u/Kurth_Bemis)\
**Post date:** [November 23, 2006, 7:15pm UTC](https://www.ruby-forum.com/t/boolean-to-text/77035/6 "2006-11-23T19:15:39Z")

</div>

Xavier N. wrote:

> thing.is\_organic = true  
> thing.toggle! :is\_organic  
> thing.is\_organic? # provided by AR if type is boolean
> 
> nonorganics = Thing.find\_all\_by\_is\_organic(false)

Suppose I miss the C++ metamacro trick. Suppose I have global constants:

YoDude = 2  
WhatsUp = 3

Now I want a 2 to produce ‘YoDude’ as a string, and 3 to produce  
‘WhatsUp’.  
Preferrably without overloading 2 and 3, and without creating a new  
lookup  
table. (That would happen if we go over 10 or so constants and I return  
control to the OnsiteCustomer.)

How do I do an enumeration that can reflect its values as strings?

–  
Phlip  
[Redirecting...](http://www.greencheese.us/ZeekLand) ← NOT a blog!!!
