Sha256: 15aa41115e155573cd0b42c6b0aca78e7580f135ed2f527ffa088934bed4423d

Contents?: true

Size: 645 Bytes

Versions: 111

Compression:

Stored size: 645 Bytes

Contents

module Picky

  module Generators

    module Weights

      # Uses a dynamic weight.
      #
      # Note: This is not saved.
      #
      # Examples:
      #   * Picky::Weights::Dynamic.new do |str_or_sym|
      #       sym_or_str * length
      #     end
      #
      class Dynamic < Stub

        # Give it a block that takes a string/symbol
        # and returns a weight.
        #
        def initialize &calculation
          @calculation = calculation
        end

        # Calls the block to calculate the weight.
        #
        def [] str_or_sym
          @calculation.call str_or_sym
        end

      end

    end

  end

end

Version data entries

111 entries across 111 versions & 1 rubygems

Version Path
picky-4.31.3 lib/picky/generators/weights/dynamic.rb
picky-4.31.2 lib/picky/generators/weights/dynamic.rb
picky-4.31.1 lib/picky/generators/weights/dynamic.rb
picky-4.31.0 lib/picky/generators/weights/dynamic.rb
picky-4.30.0 lib/picky/generators/weights/dynamic.rb
picky-4.29.0 lib/picky/generators/weights/dynamic.rb
picky-4.28.1 lib/picky/generators/weights/dynamic.rb
picky-4.27.1 lib/picky/generators/weights/dynamic.rb
picky-4.27.0 lib/picky/generators/weights/dynamic.rb
picky-4.26.2 lib/picky/generators/weights/dynamic.rb
picky-4.26.1 lib/picky/generators/weights/dynamic.rb
picky-4.26.0 lib/picky/generators/weights/dynamic.rb
picky-4.25.3 lib/picky/generators/weights/dynamic.rb
picky-4.25.2 lib/picky/generators/weights/dynamic.rb
picky-4.25.1 lib/picky/generators/weights/dynamic.rb
picky-4.25.0 lib/picky/generators/weights/dynamic.rb
picky-4.24.0 lib/picky/generators/weights/dynamic.rb
picky-4.23.2 lib/picky/generators/weights/dynamic.rb
picky-4.23.1 lib/picky/generators/weights/dynamic.rb
picky-4.23.0 lib/picky/generators/weights/dynamic.rb