Class: Necromancer::ArrayConverters::ArrayToSetConverter

Inherits:
Converter
  • Object
show all
Defined in:
lib/necromancer/converters/array.rb

Overview

An object that converts an array to a set

Instance Attribute Summary

Attributes inherited from Converter

#convert, #source, #target

Instance Method Summary collapse

Methods inherited from Converter

create, #fail_conversion_type, #initialize

Constructor Details

This class inherits a constructor from Necromancer::Converter

Instance Method Details

#call(value, options = {}) ⇒ Object

Convert an array to a set

Examples:

converter.call([:x, :y, :x, 1, 2, 1])  # => <Set: {:x, :y, 1, 2}>

Parameters:

  • value (Array)

    the array to convert



99
100
101
102
103
104
105
106
# File 'lib/necromancer/converters/array.rb', line 99

def call(value, options = {})
  strict = options.fetch(:strict, config.strict)
  begin
    value.to_set
  rescue
    strict ? fail_conversion_type(value) : value
  end
end