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.5.5 lib/picky/generators/weights/dynamic.rb
picky-4.5.4 lib/picky/generators/weights/dynamic.rb
picky-4.5.3 lib/picky/generators/weights/dynamic.rb
picky-4.5.2 lib/picky/generators/weights/dynamic.rb
picky-4.5.1 lib/picky/generators/weights/dynamic.rb
picky-4.5.0 lib/picky/generators/weights/dynamic.rb
picky-4.4.2 lib/picky/generators/weights/dynamic.rb
picky-4.4.1 lib/picky/generators/weights/dynamic.rb
picky-4.4.0 lib/picky/generators/weights/dynamic.rb
picky-4.3.2 lib/picky/generators/weights/dynamic.rb
picky-4.3.1 lib/picky/generators/weights/dynamic.rb
picky-4.3.0 lib/picky/generators/weights/dynamic.rb
picky-4.2.4 lib/picky/generators/weights/dynamic.rb
picky-4.2.3 lib/picky/generators/weights/dynamic.rb
picky-4.2.2 lib/picky/generators/weights/dynamic.rb
picky-4.2.1 lib/picky/generators/weights/dynamic.rb
picky-4.2.0 lib/picky/generators/weights/dynamic.rb
picky-4.1.0 lib/picky/generators/weights/dynamic.rb
picky-4.0.9 lib/picky/generators/weights/dynamic.rb
picky-4.0.8 lib/picky/generators/weights/dynamic.rb