Class: Picky::Generators::Weights::Dynamic

Inherits:
Stub show all
Defined in:
lib/picky/generators/weights/dynamic.rb

Overview

Uses a dynamic weight.

Note: This is not saved.

Examples:

* Picky::Weights::Dynamic.new do |str_or_sym|
    sym_or_str * length
  end

Instance Method Summary collapse

Methods inherited from Stub

#[]=, #clear, #delete, #saved?, #weight_for

Methods inherited from Strategy

#saved?, #to_s

Constructor Details

#initialize(&calculation) ⇒ Dynamic

Give it a block that takes a string/symbol and returns a weight.



21
22
23
# File 'lib/picky/generators/weights/dynamic.rb', line 21

def initialize &calculation
  @calculation = calculation
end

Instance Method Details

#[](str_or_sym) ⇒ Object

Calls the block to calculate the weight.



27
28
29
# File 'lib/picky/generators/weights/dynamic.rb', line 27

def [] str_or_sym
  @calculation.call str_or_sym
end