Class: Picky::Generators::Weights::Constant

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

Overview

Uses a constant weight. Default is 0.0.

Note: This is not saved.

Examples:

* Picky::Weights::Constant.new       # Uses 0.0 as a constant weight.
* Picky::Weights::Constant.new(3.14) # Uses 3.14 as a constant weight.

Instance Method Summary collapse

Methods inherited from Stub

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

Methods inherited from Strategy

#saved?, #to_s

Constructor Details

#initialize(weight = 0.0) ⇒ Constant

Returns a new instance of Constant.



18
19
20
# File 'lib/picky/generators/weights/constant.rb', line 18

def initialize weight = 0.0
  @weight = weight
end

Instance Method Details

#[](_) ⇒ Object

Always returns the constant weight, except if there are no ids.



25
26
27
# File 'lib/picky/generators/weights/constant.rb', line 25

def [] _
  @weight
end

#weight_for(_) ⇒ Object

Returns the constant weight, except if there are no ids.

Not really used, but is more correct this way.



35
36
37
# File 'lib/picky/generators/weights/constant.rb', line 35

def weight_for _
  @weight
end