Refactor into a class method.

Discussion in 'Ruby' started by Ruby Geo, Dec 13, 2007.

  1. Ruby Geo

    Ruby Geo Guest

    objects = [bsn0, bsn1, bsn2, bsn3, bsn4]
    search = ["Sole Trader"]
    results = objects.select do |b|
    match = true
    catch:)success) do
    search.each{|s| throw :success if b.my_keywords.include?(s) }
    match = false
    end
    match

    end
    puts (" ")
    puts "Search Results"
    puts (" ")
    results.each{|r| puts r }
    --
    Posted via http://www.ruby-forum.com/.
    Ruby Geo, Dec 13, 2007
    #1
    1. Advertising

  2. 2007/12/13, Ruby Geo <>:
    > objects = [bsn0, bsn1, bsn2, bsn3, bsn4]
    > search = ["Sole Trader"]
    > results = objects.select do |b|
    > match = true
    > catch:)success) do
    > search.each{|s| throw :success if b.my_keywords.include?(s) }


    ^^^^^^^^
    I suggest you use Enumerable#any? instead of #each here and throw away
    the catch throw logic.

    > match = false
    > end
    > match
    >
    > end
    > puts (" ")
    > puts "Search Results"
    > puts (" ")
    > results.each{|r| puts r }


    What was the question again?

    robert

    --
    use.inject do |as, often| as.you_can - without end
    Robert Klemme, Dec 13, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VisionSet

    Mother of a Refactor

    VisionSet, Jul 31, 2006, in forum: Java
    Replies:
    11
    Views:
    609
    Luke Webber
    Aug 1, 2006
  2. VisionSet
    Replies:
    3
    Views:
    307
    VisionSet
    Aug 8, 2006
  3. Replies:
    12
    Views:
    522
  4. Steven Nagy

    Converted ASP.NET project: Refactor pages

    Steven Nagy, Oct 16, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    291
    Cowboy \(Gregory A. Beamer\)
    Oct 16, 2006
  5. James B. Byrne

    Ruby script to Module/Class refactor

    James B. Byrne, Feb 15, 2006, in forum: Ruby
    Replies:
    10
    Views:
    230
    James Byrne
    Feb 24, 2006
Loading...

Share This Page