Sha256: 111a82ba35746a47c564fd6a08563f6d09a016faf8c619aa42a5e30123f1b3a0

Contents?: true

Size: 691 Bytes

Versions: 1

Compression:

Stored size: 691 Bytes

Contents

module Grokdown
  module Composing
    def self.extended(base) = base.include(InstanceMethods)

    def can_compose?(object) = public_instance_methods.include?(composition_method(object))

    def composition_method(object)
      :"add_#{object.class.name.gsub(/#<.*>::/,"").gsub("::", "_").gsub(/([A-Z])(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) { ($1 || $2) << "_" }.downcase}" if object.class.name
    end

    module InstanceMethods
      def can_compose?(object) = self.class.can_compose?(object)

      def composition_method(object) = self.class.composition_method(object)

      def add_composable(object)
        public_send(composition_method(object), object)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grokdown-0.4.0 lib/grokdown/composing.rb