Robert Klemme
8/3/2007 12:17:00 PM
2007/8/3, Kyle Schmitt <kyleaschmitt@gmail.com>:
> 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
>
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