Module: Pry::Config::Behavior::Builder

Defined in:
lib/pry/config/behavior.rb

Instance Method Summary collapse

Instance Method Details

#assign(attributes, default = nil) ⇒ Pry::Config

Returns a new Behavior, non-recursively (unlike #from_hash).

Parameters:

  • attributes (Hash)

    a hash to initialize an instance of self with.

  • default (Pry::Config, nil) (defaults to: nil)

    a default, or nil for none.

Returns:



17
18
19
20
21
# File 'lib/pry/config/behavior.rb', line 17

def assign(attributes, default = nil)
  new(default).tap do |behavior|
    behavior.merge!(attributes)
  end
end

#from_hash(attributes, default = nil) ⇒ Pry::Config

Returns a new Behavior, recursively walking attributes.

Parameters:

  • attributes (Hash)

    a hash to initialize an instance of self with.

  • default (Pry::Config, nil) (defaults to: nil)

    a default, or nil for none.

Returns:



35
36
37
38
39
40
41
# File 'lib/pry/config/behavior.rb', line 35

def from_hash(attributes, default = nil)
  new(default).tap do |config|
    attributes.each do |key,value|
      config[key] = Hash === value ? from_hash(value, nil) : value
    end
  end
end