Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Add some methods to all strings.
- class String
- def says(something)
- @body = something
- rebuild
- end
- def to(someone)
- @to = someone
- rebuild
- end
- def in_anger
- @punctuation = "!!!"
- rebuild
- end
- def rebuild
- @punctuation ||= "."
- @from ||= self.clone
- @body ||= ""
- @to ||= ""
- self.replace(@body)
- self << ", " unless @body.empty? || @to.empty?
- self << @to + @punctuation
- self << " Sincerely, #{@from}." unless @from.empty?
- self
- end
- end
- # Say some stuff!
- puts "Justin".says("Hello")
- puts "Justin".says("Good bye").to("Kevin")
- puts "All of Florida".says("Fuck off").to("hurricanes").in_anger
- # Outputs:
- # Hello. Sincerely, Justin.
- # Good bye, Kevin. Sincerely, Justin.
- # Fuck off, hurricanes!!! Sincerely, All of Florida.
Add Comment
Please, Sign In to add comment