Sha256: cd444272396e78213f5aac376fa9fee128dfb9944116caf90f6be0854f33da1e

Contents?: true

Size: 648 Bytes

Versions: 21

Compression:

Stored size: 648 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 < Runtime

        # 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

21 entries across 21 versions & 1 rubygems

Version Path
picky-3.5.1 lib/picky/generators/weights/dynamic.rb