Skip to content

Latest commit

 

History

History
72 lines (49 loc) · 1.66 KB

README.md

File metadata and controls

72 lines (49 loc) · 1.66 KB

Named

Give anonymous modules and classes names when they are inspected.

Build Status Code Climate

Usage

Named modules

fancy_module = Named::Module.new('FancyModule') do
  def module_method
    puts 'Hello from the module'
  end
end

fancy_module.inspect # => "Named::Module:FancyModule:0x7fa9ea9e6178"

Named classes

# 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"

Using them together

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'

Installation

Add this line to your application's Gemfile:

gem 'named'

And then execute:

$ bundle

Or install it yourself as:

$ gem install named

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request