Permalink
Browse files

Extend Class to support Foo::Bar.basename # => 'Bar'

  • Loading branch information...
1 parent a433d97 commit 68b4f57529bada6c2690c51b19ec4f5c643f5b0d @justinko justinko committed Feb 9, 2012
Showing with 22 additions and 0 deletions.
  1. +1 −0 lib/mutant.rb
  2. +8 −0 lib/mutant/extensions.rb
  3. +13 −0 spec/mutant/extensions_spec.rb
View
1 lib/mutant.rb
@@ -1,3 +1,4 @@
+require 'mutant/extensions'
require 'mutant/formatter'
require 'mutant/implementation'
require 'mutant/literal'
View
8 lib/mutant/extensions.rb
@@ -0,0 +1,8 @@
+module ClassExtensions
+ def basename
+ name.split('::').last
+ end
+end
+
+Class.send :include, ClassExtensions
+Rubinius::AST::Node.send :include, ClassExtensions
View
13 spec/mutant/extensions_spec.rb
@@ -0,0 +1,13 @@
+require 'spec_helper'
+
+describe Class do
+ describe '#basename' do
+ context 'when called on Thing::Spirit' do
+ setup_thing { class Spirit; end }
+
+ it 'returns "Spirit"' do
+ Thing::Spirit.basename.should eq('Spirit')
+ end
+ end
+ end
+end

0 comments on commit 68b4f57

Please sign in to comment.