Skip to content

Instantly share code, notes, and snippets.

@ahoward
Created April 27, 2011 15:55
Show Gist options
  • Save ahoward/944532 to your computer and use it in GitHub Desktop.
Save ahoward/944532 to your computer and use it in GitHub Desktop.

Revisions

  1. ahoward revised this gist Apr 27, 2011. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions case-splat.rb
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    compile = proc{|w| a, b = w[0..0], w[1..-1]; /^\s*#{ a }(?:#{ b })?\s*$/i}

    MalePatterns =
    %w( man male boy ).
    map(&compile)
  2. ahoward created this gist Apr 27, 2011.
    18 changes: 18 additions & 0 deletions case-splat.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    MalePatterns =
    %w( man male boy ).
    map(&compile)

    FemalePatterns =
    %w( woman female girl ).
    map(&compile)

    def normalize_gender!
    gender =
    case self.gender.to_s
    when *MalePatterns
    'm'
    when *FemalePatterns
    'f'
    end
    self.gender = gender
    end