Sha256: d2ecd9d3a55898ab38e1bc0038756f28bc2e75e5654ae1ec0c6a4a84ed2fbaf6

Contents?: true

Size: 852 Bytes

Versions: 1

Compression:

Stored size: 852 Bytes

Contents

class Hash
  def assert_valid_keys(*valid_keys)
    # Lifted from activesupport
    unknown_keys = keys - [valid_keys].flatten
    raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty?
  end
  
  def symbolize_keys!
    # Lifted from merb
    each do |key, value|
      sym = key.respond_to?(:to_sym) ? key.to_sym : key
      self[sym] = value
      delete(key) unless key == sym
    end
    self
  end
end

class Array
  def assert_valid_elements(*valid_elements)
    # Lifted from activesupport
    unknown_elements = self - [valid_elements].flatten
    raise(ArgumentError, "Unknown elements(s): #{unknown_elements.join(", ")}") unless unknown_elements.empty?
  end

  def symbolize_elements!
    collect! do |element|
      element.respond_to?(:to_sym) ? element.to_sym : element 
    end
    self
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kissifer-rack-ticket-office-0.0.1 lib/rack/ticket-office/monkey_patches.rb