Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/derp.rb

Overview

What’s a gem without a monkeypatch?

Constant Summary collapse

Morse =
{
  'a' => 'herpderp',
  'b' => 'derpherpherpherp',
  'c' => 'derpherpderpherp',
  'd' => 'derpherpherp',
  'e' => 'herp',
  'f' => 'herpherpderpherp',
  'g' => 'derpderpherp',
  'h' => 'herpherpherpherp',
  'i' => 'herpherp',
  'j' => 'herpderpderpderp',
  'k' => 'derpherpderp',
  'l' => 'herpderpherpherp',
  'm' => 'derpderp',
  'n' => 'derpherp',
  'o' => 'derpderpderp',
  'p' => 'herpderpderpherp',
  'q' => 'derpderpherpderp',
  'r' => 'herpderpherp',
  's' => 'herpherpherp',
  't' => 'derp',
  'u' => 'herpherpderp',
  'v' => 'herpherpherpderp',
  'w' => 'herpderpderp',
  'x' => 'derpherpherpderp',
  'y' => 'derpherpderpderp',
  'z' => 'derpderpherpherp',
  ' ' => '.',
  '1' => 'herpherpderpderp',
  '2' => 'herpderpherpderp',
  '3' => 'derpderpderpderp',
  '4' => 'derpherpherpherpderp',
  '5' => 'derpderpderpderpderp',
  '6' => 'derpherpherpherpherp',
  '7' => 'herpderpderpderpderp',
  '8' => 'herpherpherpherpherp',
  '9' => 'derpherpherpderpderp',
  '0' => 'herpherpderpderpherp'
}

Instance Method Summary collapse

Instance Method Details

#from_derpObject

The inverse of ‘to_derp`, `from_derp` turns a derp string back into a normal `String`.



67
68
69
70
71
72
# File 'lib/derp.rb', line 67

def from_derp
  inverted = Morse.invert
  self.split.collect do |w|
    inverted[w] + " " unless inverted[w].nil?
  end.join.gsub(/\s([a-z\s])/, '\1').rstrip
end

#to_derpObject

This method converts a string to a derp string. Not to be confused with a BenString, the derp string is simply a ‘String` with only ’herp’ and ‘derp’ in it.



59
60
61
62
63
# File 'lib/derp.rb', line 59

def to_derp
  self.downcase.split(//).collect do |c|
    Morse[c] + " " unless Morse[c].nil?
  end.join.rstrip
end