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:



19
20
21
22
23
# File 'lib/pry/config/behavior.rb', line 19

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:



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

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