MyString = Class.new(String) MyString.define_singleton_method(:alphabet, lambda { 'abc' }) MyString.send(:define_method, :exclaim, lambda { |count = 1| "#{self}#{exclamation_mark count}" }) MyString.send(:define_method, :exclamation_mark, lambda { |count| '!' * count }) MyString.send(:alias_method, :!, :exclaim) MyString.send(:private, :exclamation_mark) require 'rspec/autorun' describe MyString do describe '.alphabet' do specify { MyString.alphabet.should == 'abc' } end describe '#exclaim' do subject { MyString.new('james') } specify { subject.exclaim.should == 'james!' } specify { subject.exclaim(4).should == 'james!!!!' } end describe '#!' do subject { MyString.new('james') } specify { subject.!.should == 'james!' } it 'should be the same even if #exclaim is redefined' do MyString.class_eval { define_method(:exclaim) { '' } } subject.!.should == 'james!' end end describe '#exclamation_mark' do specify { subject.should_not respond_to(:exclamation_mark) } end end