Forum: Ruby cleaner way?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9dec3df8319c613f6f4f14a27da0fdb4?d=identicon&s=25 Kyle Schmitt (Guest)
on 2007-08-03 01:10
(Received via mailing list)
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
2ff47d48fde7f8f2d1e25ab7ccc87d00?d=identicon&s=25 Peter Brown (Guest)
on 2007-08-03 01:26
(Received via mailing list)
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
Ce8b03e5750097942c58e12b46724312?d=identicon&s=25 Giles Bowkett (Guest)
on 2007-08-03 01:40
(Received via mailing list)
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.com/node/418

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

--
Giles Bowkett

Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2007-08-03 14:17
(Received via mailing list)
2007/8/3, Kyle Schmitt <kyleaschmitt@gmail.com>:
> 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
A9c4658e9e475e13d790ae419acf01b6?d=identicon&s=25 Simon Kröger (Guest)
on 2007-08-04 00:41
(Received via mailing list)
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
This topic is locked and can not be replied to.