Give anonymous modules and classes names when they are inspected.
fancy_module = Named::Module.new('FancyModule') do
def module_method
puts 'Hello from the module'
end
end
fancy_module.inspect # => "Named::Module:FancyModule:0x7fa9ea9e6178"
# subclasses Array
fancy_class = Named::Class.new('FancyClass', Array) do
def class_method
puts 'Hello from the class'
end
end
# Inspection string shows the superclass
fancy_class.inspect => "Named::Class:Array:FancyClass:0x7fa9ea8aaea8"
fancy_class.send(:include, fancy_module)
fancy_class.ancestors # => [Named::Class:Array:FancyClass:0x7fa9ea8aaea8,
# Named::Module:FancyModule:0x7fa9ea9e6178,
# Named::Class, Named::Naming,
# Array, Kernel, BasicObject]
instance = fancy_class.new
instance.module_method # => 'Hello from the module'
instance.class_method # => 'Hello from the class'
Add this line to your application's Gemfile:
gem 'named'
And then execute:
$ bundle
Or install it yourself as:
$ gem install named
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request