# Cleaner way?

**URL:** <https://www.ruby-forum.com/t/cleaner-way/111142>\
**Category:** Ruby\
**Created:** [August 3, 2007, 1:10am UTC](https://www.ruby-forum.com/t/cleaner-way/111142 "2007-08-03T01:10:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyle\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f6c823/32.png) [@kyle\_s](https://www.ruby-forum.com/u/kyle_s)\
**Post date:** [August 3, 2007, 1:10am UTC](https://www.ruby-forum.com/t/cleaner-way/111142/1 "2007-08-03T01:10:34Z")

</div>

I’ll first admit this is a lot cleaner and more succinct than my first  
pass of it… but well  
Is there a way to make this case and send block clearer and cleaner?

Thanks,  
Kyle

def getProperties(type=:textField)

```
logWarning("Please use a symbol, not a string for :#{type.to_s}")

```

unless type.is\_a?Symbol

```
converter = case type.to_sym
  when :textField,:text_field then "clone"
  when :text,:t,:value then "value"
  when :html then "html"
  else logError("I'm not familiar with :#{type.to_s}, please try

```

another type.")  
end

```
{:name=>@ie.text_field(:id,/EnvironmentTextEdit/).send(converter),
:start=>@ie.text_field(:id,/StartYearEdit/).send(converter),
:years=>@ie.text_field(:id,/NumberOfYearsEdit/).send(converter)}

```

end

---

<div class="post-metadata">

**Author:** ![kyle\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f6c823/32.png) [@kyle\_s](https://www.ruby-forum.com/u/kyle_s)\
**Post date:** [August 3, 2007, 1:26am UTC](https://www.ruby-forum.com/t/cleaner-way/111142/2 "2007-08-03T01:26:35Z")

</div>

I recently upgraded rails from 1.2.2 to 1.2.3 with (I believe) this  
command:

gem install rails --system

Somehow this has caused gem to ignore most of my previously installed  
gems.

THe directory /usr/local/lib/ruby/gems/1.8/gems contains:

RedCloth-3.0.4 actionwebservice-1.1.2  
acts\_as\_searchable-0.1.0 mongrel-0.3.13.3  
rails-1.1.2 sources-0.0.1  
actionmailer-1.2.1 actionwebservice-1.1.4  
capistrano-1.1.0 mongrel\_cluster-0.2.0  
rails-1.1.4  
actionmailer-1.2.3 activerecord-1.14.2  
daemons-1.0.1 needle-1.3.0  
rake-0.7.1  
actionpack-1.12.1 activerecord-1.14.3  
fixrbconfig-1.2 net-sftp-1.1.0  
rcss-0.3.1  
actionpack-1.12.3 activesupport-1.3.1  
gem\_plugin-0.2.1 net-ssh-1.0.9  
rmagick-1.13.0

However, gem list only shows these:

\*\*\* LOCAL GEMS \*\*\*

actionmailer (1.3.3)

actionpack (1.13.3)

actionwebservice (1.2.3)

activerecord (1.15.3)

activesupport (1.4.2)

hpricot (0.6)

rails (1.2.3)

rake (0.7.3)

rfacebook (0.7.1)

sources (0.0.1)

It was a huge hassle to get some of these installed on OSX (like  
rmagick) and I’d rather not have to re-do them.

How can I fix this?

THanks

---

<div class="post-metadata">

**Author:** ![kyle\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f6c823/32.png) [@kyle\_s](https://www.ruby-forum.com/u/kyle_s)\
**Post date:** [August 3, 2007, 1:40am UTC](https://www.ruby-forum.com/t/cleaner-way/111142/3 "2007-08-03T01:40:35Z")

</div>

On 8/2/07, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I recently upgraded rails from 1.2.2 to 1.2.3 with (I believe) this  
> command:
> 
> gem install rails --system
> 
> Somehow this has caused gem to ignore most of my previously installed  
> gems.

I’m not sure, but I’d start here:

[http://armyofevilrobots.com/node/418](http://armyofevilrobots.com/node/418)

By the way, I don’t actually see a --system option on install in gem  
help.

–  
Giles B.

Blog: [http://gilesbowkett.blogspot.com](http://gilesbowkett.blogspot.com)  
Portfolio: [http://www.gilesgoatboy.org](http://www.gilesgoatboy.org)

---

<div class="post-metadata">

**Author:** ![kyle\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f6c823/32.png) [@kyle\_s](https://www.ruby-forum.com/u/kyle_s)\
**Post date:** [August 3, 2007, 2:17pm UTC](https://www.ruby-forum.com/t/cleaner-way/111142/4 "2007-08-03T14:17:59Z")

</div>

2007/8/3, Kyle S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> unless type.is\_a?Symbol  
> {:name=\>@ie.text\_field(:id,/EnvironmentTextEdit/).send(converter),  
> :start=\>@ie.text\_field(:id,/StartYearEdit/).send(converter),  
> :years=\>@ie.text\_field(:id,/NumberOfYearsEdit/).send(converter)}  
> end

How about

MAP={  
:text\_field =\> “clone”,  
:textField =\> “clone”,  
:text =\> “value”,  
:t =\> “value”,  
:value =\> “value”,  
:html =\> “html”  
}

def get\_properties(type=:text\_field)  
logWarning(“Please use a symbol, not a string for :#{type.to\_s}”)  
unless Symbol === type

converter = MAP[:type] or  
logError(“I’m not familiar with :#{type.to\_s}, please try another  
type.”)

{  
:name=\>@ie.text\_field(:id,/EnvironmentTextEdit/).send(converter),  
:start=\>@ie.text\_field(:id,/StartYearEdit/).send(converter),  
:years=\>@ie.text\_field(:id,/NumberOfYearsEdit/).send(converter)  
}  
end

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![kyle\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f6c823/32.png) [@kyle\_s](https://www.ruby-forum.com/u/kyle_s)\
**Post date:** [August 4, 2007, 12:41am UTC](https://www.ruby-forum.com/t/cleaner-way/111142/5 "2007-08-04T00:41:21Z")

</div>

Kyle S. schrieb:

> I’ll first admit this is a lot cleaner and more succinct than my first  
> pass of it… but well  
> Is there a way to make this case and send block clearer and cleaner?

## I would only resort to #send and friends if neccessarity occurs:

def convert value, type  
case type.to\_sym  
when :textField,:text\_field then value.clone  
when :text,:t,:value then value.value  
when :html then value.html  
else value  
end  
end

## def getProperties type = :textField { :name =\> convert(@ie.text\_field(:id, /EnvironmentTextEdit/), type), :start =\> convert(@ie.text\_field(:id, /StartYearEdit/), type), :years =\> convert(@ie.text\_field(:id, /NumberOfYearsEdit/), type) } end

thats much more pleasing to my eye, but YMMV

cheers

Simon
