Class: Lite::Containers::Helpers::KeyExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/lite/containers/helpers/key_extractor.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ KeyExtractor

Returns a new instance of KeyExtractor.



19
20
21
# File 'lib/lite/containers/helpers/key_extractor.rb', line 19

def initialize(block)
  @block = block
end

Class Method Details

.instance(input) ⇒ Object

Raises:



9
10
11
12
13
14
15
# File 'lib/lite/containers/helpers/key_extractor.rb', line 9

def self.instance(input)
  return if input.nil?
  return input if input.respond_to? :to_key
  return new input if input.is_a? Proc

  raise Error, "Expected nil, key extractor or a proc, got #{input.inspect}"
end

Instance Method Details

#to_key(element) ⇒ Object



23
24
25
# File 'lib/lite/containers/helpers/key_extractor.rb', line 23

def to_key(element)
  @block.call(element)
end