# Re: How to improve this kind of API?

**URL:** <https://www.ruby-forum.com/t/re-how-to-improve-this-kind-of-api/65120>\
**Category:** Ruby\
**Created:** [February 9, 2006, 8:52pm UTC](https://www.ruby-forum.com/t/re-how-to-improve-this-kind-of-api/65120 "2006-02-09T20:52:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [February 9, 2006, 8:52pm UTC](https://www.ruby-forum.com/t/re-how-to-improve-this-kind-of-api/65120/1 "2006-02-09T20:52:07Z")

</div>

> it always boils down to some widget attribute that can have a
> 
> splitter3.expanded? :bottom\_left  
> Thanks in advance for your suggestions!
> 
> Lyle

FWIW, I think what you’ve posted here looks good, so long as I could use  
strings as well, e.g. splitter.expand(“top\_left”).

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [February 9, 2006, 9:25pm UTC](https://www.ruby-forum.com/t/re-how-to-improve-this-kind-of-api/65120/2 "2006-02-09T21:25:40Z")

</div>

On Fri, 10 Feb 2006, Berger, Daniel wrote:

> > it always boils down to some widget attribute that can have a
> > 
> > splitter3.expanded? :bottom\_left  
> > Thanks in advance for your suggestions!
> > 
> > Lyle
> 
> FWIW, I think what you’ve posted here looks good, so long as I could use  
> strings as well, e.g. splitter.expand(“top\_left”).

indeed. a symbols only api is evil - makes reading config info from  
files/yaml a pain.

a config method is also quite nice

splitter.configure {  
expand ‘top\_left’  
something ‘foobar’  
}

which should also take a hash

splitter.configured(  
‘expand’ =\> ‘top\_left’,  
‘something’ =\> ‘foobar’  
)

which makes

splitter.configure(YAML::load(IO:;read(‘config.yml’)))

a one liner.

if config.yml has

* * *

expand : top\_left  
something : foobar

in it.

regards.

-a

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [February 9, 2006, 9:46pm UTC](https://www.ruby-forum.com/t/re-how-to-improve-this-kind-of-api/65120/3 "2006-02-09T21:46:19Z")

</div>

On 2/9/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> indeed. a symbols only api is evil - makes reading config info from  
> files/yaml a pain…

> something : foobar
> 
> in it.

How would one specify (especially in the YAML representation) that  
both the “top\_left” and “top\_right” bits for “expand” should be set?  
Would it look something like this:

```
---
expand:
  - top_left
  -top_right
something: foobar

```

I don’t have as much exposure to YAML as I probably should. 😉

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [February 9, 2006, 10:42pm UTC](https://www.ruby-forum.com/t/re-how-to-improve-this-kind-of-api/65120/4 "2006-02-09T22:42:28Z")

</div>

On Thu, 9 Feb 2006, Lyle J. wrote:

> > 
> 
> How would one specify (especially in the YAML representation) that  
> both the “top\_left” and “top\_right” bits for “expand” should be set?  
> Would it look something like this:
> 
> * * *
> 
> expand:  
> - top\_left  
> -top\_right  
> something: foobar
> 
> I don’t have as much exposure to YAML as I probably should. 😉

exactly right.

btw. it’s easy to figure out:

## harp:~ \> ruby -r yaml -e’ y “expand” =\> [“top\_left”, “top\_right”], “foo” =\> “bar” ’

expand:

- top\_left
- top\_right  
foo: bar

cheers.

-a
