Sha256: 28d2c7f3a08c4d2267149641d1eb394434af0cfa2fc6329c3d2d9c6612ff05c0

Contents?: true

Size: 500 Bytes

Versions: 3

Compression:

Stored size: 500 Bytes

Contents

class Object
  # Set setter methods and/or vars using a hash (or assoc array).
  #
  #   require 'facet/object/set_with'
  #
  def set_with(*args)
    if args.first.is_a?(Hash)  #or args[0].is_a?(Array)
      iv_val_pairs = args.first
    else
      raise ArgumentError, "Hash required for assigning multiple variables" if args.length > 2
      iv_val_pairs = { args[0] => args[1] }
    end
    iv_val_pairs.each_pair do |k,v|
      self.send( "#{k}=", v ) #if respond_to?("#{k}=")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
facets-0.7.0 lib/facet/object/set_with.rb
facets-0.7.1 lib/facet/object/set_with.rb
facets-0.7.2 lib/facet/object/set_with.rb