[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

cleaner way?

Kyle Schmitt

8/2/2007 11:10:00 PM

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

5 Answers

Peter Brown

8/2/2007 11:26:00 PM

0

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

Giles Bowkett

8/2/2007 11:40:00 PM

0

On 8/2/07, Peter Brown <peter@flippyhead.com> 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.co...

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

--
Giles Bowkett

Blog: http://gilesbowkett.bl...
Portfolio: http://www.gilesg...

Robert Klemme

8/3/2007 12:17:00 PM

0

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

Simon Kröger

8/3/2007 10:40:00 PM

0

Kyle Schmitt 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

Jim G.

11/12/2012 8:21:00 PM

0

shawn sent the following on Fri, 09 Nov 2012 13:57:17 -0500:
> On Fri, 09 Nov 2012 12:09:11 -0500, Mason Barge <masonbarge@gmail.com>
> wrote:
>
> >On Sun, 28 Oct 2012 21:19:21 +0000 (UTC), "Adam H. Kerman"
> ><ahk@chinet.com> wrote:
> >
> >>Mason Barge <masonbarge@gmail.com> wrote:
> >>>"Adam H. Kerman" <ahk@chinet.com> wrote:
> >>>>Mason Barge <masonbarge@gmail.com> wrote:
> >>
> >>>>>Yeah, but I think we all understand that Trump's intention here is not to
> >>>>>help charity, but to embarrass Obama. Trump's an utter buffoon, but he
> >>>>>did manage to embarrass Obama a bit.
> >>
> >>>>As Obama hasn't bitten the troll, how do you figure that? I haven't heard
> >>>>him make a single comment on it.
> >>
> >>>It's a decent strategy. If he doesn't say anything about it, that's one
> >>>less time anything about it appears in the press.
> >>
> >>Therefore Obama has nothing to be embarrassed about. Agree?
> >
> >Well, it's obviously stale news by now. But no, not really. If I ran for
> >president, I'd be happy to make my educational transcripts public.
> >
> >(I'm almost positive that little incident with the sheep wouldn't be in a
> >transcript.)
>
> It wouldn't be written in the transcripts, but the pictures might be
> included. Why was the sheep wearing a dress?

It was the winter formal. Duh. I'm more interested in what the sheep
would have worn to the barn dance. That could have gotten awkward.

--
Jim G. | A fan of the good and the bad, but not the mediocre
"I'm really ready for this day to be over." -- Duke Crocker, HAVEN