Sha256: 4e44ee5881ece35e12861168df63db221d171f56597eb716b72aa173c7d57902

Contents?: true

Size: 1.01 KB

Versions: 16

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

class Sinclair
  class MethodBuilder
    # @api private
    # @author darthjee
    #
    # Class responsible to build methods from
    # string definitions
    #
    # @see MethodDefinition::StringDefinition
    class StringMethodBuilder < Base
      # Builds the method
      #
      # @return (see Base#build)
      def build
        klass.module_eval(code_definition, __FILE__, __LINE__ + 1)
      end

      private

      # @private
      #
      # string used for method name definition
      #
      # the string changes depending if it is
      # a class or instance method
      #
      # @return [String]
      def definition_name
        instance? ? name : "self.#{name}"
      end

      # @private
      #
      # string with the code to be defined
      #
      # @return [String]
      def code_definition
        <<-CODE
          def #{definition_name}
            #{code_line}
          end
        CODE
      end

      delegate :code_line, :name, to: :definition
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
sinclair-1.11.0 lib/sinclair/method_builder/string_method_builder.rb
sinclair-1.10.0 lib/sinclair/method_builder/string_method_builder.rb
sinclair-1.9.0 lib/sinclair/method_builder/string_method_builder.rb
sinclair-1.8.0 lib/sinclair/method_builder/string_method_builder.rb
sinclair-1.7.0 lib/sinclair/method_builder/string_method_builder.rb
sinclair-1.6.7 lib/sinclair/method_builder/string_method_builder.rb
sinclair-1.6.6 lib/sinclair/method_builder/string_method_builder.rb
sinclair-1.6.5 lib/sinclair/method_builder/string_method_builder.rb
sinclair-1.6.4 lib/sinclair/method_builder/string_method_builder.rb
sinclair-1.6.3 lib/sinclair/method_builder/string_method_builder.rb
sinclair-1.6.2 lib/sinclair/method_builder/string_method_builder.rb
sinclair-1.6.1 lib/sinclair/method_builder/string_method_builder.rb
sinclair-1.6.0 lib/sinclair/method_builder/string_method_builder.rb
sinclair-1.5.2 lib/sinclair/method_builder/string_method_builder.rb
sinclair-1.5.1 lib/sinclair/method_builder/string_method_builder.rb
sinclair-1.5.0 lib/sinclair/method_builder/string_method_builder.rb