# Initial release of Elemental

**URL:** <https://www.ruby-forum.com/t/initial-release-of-elemental/159281>\
**Category:** Ruby\
**Created:** [February 3, 2009, 1:45am UTC](https://www.ruby-forum.com/t/initial-release-of-elemental/159281 "2009-02-03T01:45:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwlang88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@mwlang88](https://www.ruby-forum.com/u/mwlang88)\
**Post date:** [February 3, 2009, 1:45am UTC](https://www.ruby-forum.com/t/initial-release-of-elemental/159281/1 "2009-02-03T01:45:39Z")

</div>

Posted By: Michael Lang  
Date: 2009-02-02 18:42  
Summary: [ANN] Initial release of Elemental  
Project: Elemental Enumerated Types

I am happy to announce the initial release of Elemental 0.1.1.

Elemental provides enumerated collection of elements that allow you to  
associate ruby symbols to arbitrary “display” values, thus allowing  
your code to think symbolically and unambiguously while giving you the  
means to easily display what end-users need to see. Additionally,  
symbols are associated with ordinal values, allowing easy storage/  
retrieval to persistent stores (databases, files, marshalling, etc) by  
saving the Element#value as appropriate (String by default, Fixnum if  
you “persist\_ordinally”).

The primary aim of Elemental is to collect and abstract literals away  
from your code logic. There’s an old programmer’s wisdom that you  
should not encode your logic using literal values, especially those  
the end-user is exposed to.

Complete details provided in README.txt

> **[GitHub - mwlang/elemental: Elemental provides enumerated collection of elements...](https://github.com/mwlang/elemental/tree/master)**
>
> master

[http://rubyforge.org/projects/elemental/](http://rubyforge.org/projects/elemental/)

Regards,

Michael

---

<div class="post-metadata">

**Author:** ![mwlang88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@mwlang88](https://www.ruby-forum.com/u/mwlang88)\
**Post date:** [February 3, 2009, 3:39am UTC](https://www.ruby-forum.com/t/initial-release-of-elemental/159281/2 "2009-02-03T03:39:43Z")

</div>

On Feb 2, 9:15 pm, Ryan D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ?
> 
> in other words, why would I want to add 250 lines of dependency code  
> where 0 seems to suffice?

As always, depends on where you want to go with it. For me, I wanted  
to catch typos immediately much like a compiled language might. I  
also wanted to associate a display value with a symbol. And I also  
wanted to have that be enumerable so I can populate a dropdown list or  
emit radio button groups and checkboxes.

Not every case calls for Elemental, but I find that it heightens my  
code’s clarity and maintainability and felt it worthy to release to  
public domain.

Michael

---

<div class="post-metadata">

**Author:** ![mwlang88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@mwlang88](https://www.ruby-forum.com/u/mwlang88)\
**Post date:** [February 3, 2009, 3:16am UTC](https://www.ruby-forum.com/t/initial-release-of-elemental/159281/3 "2009-02-03T03:16:18Z")

</div>

From your github readme:

> if my\_user.status == UserStatus::active.value  
> my\_user.favorite\_color = Color::blue

versus:

> if my\_user.status == UserStatus::ACTIVE  
> my\_user.favorite\_color = Color::BLUE

?

in other words, why would I want to add 250 lines of dependency code  
where 0 seems to suffice?

---

<div class="post-metadata">

**Author:** ![mwlang88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@mwlang88](https://www.ruby-forum.com/u/mwlang88)\
**Post date:** [February 3, 2009, 7:33am UTC](https://www.ruby-forum.com/t/initial-release-of-elemental/159281/4 "2009-02-03T07:33:39Z")

</div>

On Mon, Feb 2, 2009 at 9:15 PM, Ryan D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ?
> 
> in other words, why would I want to add 250 lines of dependency code where 0  
> seems to suffice?

Don’t be so harsh Ryan. You’d need at least two lines of code there 🙂

-greg

---

<div class="post-metadata">

**Author:** ![mwlang88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@mwlang88](https://www.ruby-forum.com/u/mwlang88)\
**Post date:** [February 3, 2009, 10:46am UTC](https://www.ruby-forum.com/t/initial-release-of-elemental/159281/5 "2009-02-03T10:46:41Z")

</div>

On Feb 2, 2009, at 18:34 , mwlang88 wrote:

> > in other words, why would I want to add 250 lines of dependency code  
> > where 0 seems to suffice?
> 
> As always, depends on where you want to go with it. For me, I wanted  
> to catch typos immediately much like a compiled language might.

immediately? how? you can’t (afaik) do better than a runtime error of  
some kind. No different than a const\_missing/NameError that you’re  
going to get with a typo’d constant name.

> I also wanted to associate a display value with a symbol.

#to\_s ? #to\_html ? #to\_whatever ? Maybe I’m not getting your point on  
this one.

> And I also wanted to have that be enumerable so I can populate a  
> dropdown list or emit radio button groups and checkboxes.

Arrays are already enumerable.

```
 # actual code from png.rb:
 Background = Color.from 0x00000000, "Transparent"
 Black = Color.from 0x000000FF, "Black"
 Blue = Color.from 0x0000FFFF, "Blue"
 Brown = Color.from 0x996633FF, "Brown"
 Bubblegum = Color.from 0xFF66FFFF, "Bubblegum"
 Cyan = Color.from 0x00FFFFFF, "Cyan"
 Gray = Color.from 0x7F7F7FFF, "Gray"
 Green = Color.from 0x00FF00FF, "Green"
 Magenta = Color.from 0xFF00FFFF, "Magenta"
 Orange = Color.from 0xFF7F00FF, "Orange"
 Purple = Color.from 0x7F007FFF, "Purple"
 Red = Color.from 0xFF0000FF, "Red"
 White = Color.from 0xFFFFFFFF, "White"
 Yellow = Color.from 0xFFFF00FF, "Yellow"

```

so it would be trivial to do:

Colors = […all of the above…]

…  
options\_from\_collection\_for\_select(Color::Colors, :to\_hex, :name)

> Not every case calls for Elemental, but I find that it heightens my  
> code’s clarity and maintainability and felt it worthy to release to  
> public domain.

Granted, the doco you have up on github is a tad on the light side,  
but I just don’t see it. Ruby seems to provide pretty good mechanisms  
for everything you’re trying to solve.

---

<div class="post-metadata">

**Author:** ![mwlang88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/57b2e6/32.png) [@mwlang88](https://www.ruby-forum.com/u/mwlang88)\
**Post date:** [February 4, 2009, 4:05am UTC](https://www.ruby-forum.com/t/initial-release-of-elemental/159281/6 "2009-02-04T04:05:49Z")

</div>

On Feb 3, 4:45 am, Ryan D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> going to get with a typo’d constant name.
> 
> ```
> Orange = Color.from 0xFF7F00FF, "Orange"
> 
> ```
> 
> options\_from\_collection\_for\_select(Color::Colors, :to\_hex, :name)
> 
> > Not every case calls for Elemental, but I find that it heightens my  
> > code’s clarity and maintainability and felt it worthy to release to  
> > public domain.
> 
> Granted, the doco you have up on github is a tad on the light side,  
> but I just don’t see it. Ruby seems to provide pretty good mechanisms  
> for everything you’re trying to solve.

This is some interesting stuff and you have just shown me a technique/  
use of arrays I haven’t encountered yet. Looks like I’m going to have  
to take myself back to school here.

Michael
