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-4.0.0pre1 lib/picky/generators/weights/dynamic.rb
picky-3.6.16 lib/picky/generators/weights/dynamic.rb
picky-3.6.15 lib/picky/generators/weights/dynamic.rb
picky-3.6.14 lib/picky/generators/weights/dynamic.rb
picky-3.6.13 lib/picky/generators/weights/dynamic.rb
picky-3.6.12 lib/picky/generators/weights/dynamic.rb
picky-3.6.11 lib/picky/generators/weights/dynamic.rb
picky-3.6.10 lib/picky/generators/weights/dynamic.rb
picky-3.6.9 lib/picky/generators/weights/dynamic.rb
picky-3.6.8 lib/picky/generators/weights/dynamic.rb
picky-3.6.7 lib/picky/generators/weights/dynamic.rb
picky-3.6.6 lib/picky/generators/weights/dynamic.rb
picky-3.6.4 lib/picky/generators/weights/dynamic.rb
picky-3.6.3 lib/picky/generators/weights/dynamic.rb
picky-3.6.2 lib/picky/generators/weights/dynamic.rb
picky-3.6.1 lib/picky/generators/weights/dynamic.rb
picky-3.6.0 lib/picky/generators/weights/dynamic.rb
picky-3.5.4 lib/picky/generators/weights/dynamic.rb
picky-3.5.3 lib/picky/generators/weights/dynamic.rb
picky-3.5.2 lib/picky/generators/weights/dynamic.rb