Skip to content

Instantly share code, notes, and snippets.

@tompng
Created May 8, 2014 16:51
Show Gist options
  • Select an option

  • Save tompng/092cd158fb6b36da62ab to your computer and use it in GitHub Desktop.

Select an option

Save tompng/092cd158fb6b36da62ab to your computer and use it in GitHub Desktop.

Revisions

  1. tompng created this gist May 8, 2014.
    21 changes: 21 additions & 0 deletions pattern.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    def get patterns
    loop do
    s = gets
    p = patterns.find{|p|p=~s}
    return [p, s] if p
    end
    end

    number = /\d+/
    word = /[a-z]+/

    pattern, text = get [number, word]
    case [pattern]
    when [number]
    puts text.to_i+1
    when [word]
    puts text.upcase
    else
    puts 'what!?'
    end