Method: Polars::Config#initialize

Defined in:
lib/polars/config.rb

#initialize(restore_defaults: false, **options) {|self.class| ... } ⇒ Config

Initialize a Config object instance for context manager usage.

Yields:

  • (self.class)
[View source]

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/polars/config.rb', line 27

def initialize(restore_defaults: false, **options)
  @original_state = self.class.save

  if restore_defaults
    self.class.restore_defaults
  end

  options.each do |opt, value|
    opt = "set_#{opt}" unless opt.to_s.start_with?("set_")
    if !self.class.respond_to?(opt)
      raise ArgumentError, "Config has no #{opt} option"
    end
    self.class.public_send(opt, value)
  end

  yield self.class

  self.class.restore_defaults.load(@original_state)
  @original_state = ""
end