Skip to content

Instantly share code, notes, and snippets.

@roidrage
Created September 17, 2008 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roidrage/11243 to your computer and use it in GitHub Desktop.
Save roidrage/11243 to your computer and use it in GitHub Desktop.
LOLstring
require 'rubygems'
require 'activesupport'
class StringProxy
def initialize(string, negate)
@string = string
@negate = negate
end
def method_missing(name, *args)
if @negate
!@string.send(name, *args)
else
@string.send(name, *args)
end
end
end
class String
def doesnt
StringProxy.new self, true
end
def can
StringProxy.new self, false
end
def has?(string = "")
!self.include? ""
end
end
if $0 == __FILE__
require "test/unit"
require 'shoulda'
class DoesntTest < Test::Unit::TestCase
context "a string the not the same" do
should "negate the given method" do
assert "horses".doesnt.start_with?("ponies")
end
end
context "a string that's the same" do
should "return true" do
assert !"ponies!".doesnt.start_with?("ponies")
end
should "can have include" do
assert "ponies".can.include?("ponies")
end
end
context "a string that can has" do
should "have a string that has" do
assert !"i".can.has?("cheezeburger")
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment