Class: String
- Inherits:
-
Object
- Object
- String
- 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', ' ' => '.' }
Instance Method Summary collapse
-
#from_derp ⇒ Object
The inverse of ‘to_derp`, `from_derp` turns a derp string back into a normal `String`.
-
#to_derp ⇒ Object
This method converts a string to a derp string.
Instance Method Details
#from_derp ⇒ Object
The inverse of ‘to_derp`, `from_derp` turns a derp string back into a normal `String`.
57 58 59 60 61 62 |
# File 'lib/derp.rb', line 57 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_derp ⇒ Object
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.
49 50 51 52 53 |
# File 'lib/derp.rb', line 49 def to_derp self.downcase.split(//).collect do |c| Morse[c] + " " unless Morse[c].nil? end.join.rstrip end |