class ProperProperties::Properties

Simple representation of a properties file content by an extension of a Hash object a la ActiveSupport::HashWithIndifferentAccess, with underlying symbol keys

Public Instance Methods

[](key) click to toggle source
# File lib/proper_properties/properties.rb, line 55
def [](key)
  self.fetch(key)
end
[]=(key, value) click to toggle source

Assigns a new value to the hash:

hash = ProperProperties::Properties.new
hash[:key] = 'value'

This value can be later fetched using either :key or +‘key’+.

Calls superclass method
# File lib/proper_properties/properties.rb, line 12
def []=(key, value)
  super(convert_key(key), value)
end
delete(key) click to toggle source

Removes the specified key from the hash.

Calls superclass method
# File lib/proper_properties/properties.rb, line 51
def delete(key)
  super(convert_key(key))
end
fetch(key, *extras) click to toggle source

Same as Hash#fetch where the key passed as argument can be either a string or a symbol:

counters = ProperProperties::Properties.new
counters[:foo] = 1

counters.fetch('foo')          # => 1
counters.fetch(:bar, 0)        # => 0
counters.fetch(:bar) {|key| 0} # => 0
counters.fetch(:zoo)           # => KeyError: key not found: "zoo"
Calls superclass method
# File lib/proper_properties/properties.rb, line 36
def fetch(key, *extras)
  super(convert_key(key), *extras)
end
key?(key) click to toggle source

Checks the hash for a key matching the argument passed in:

hash = ProperProperties::Properties.new
hash['key'] = 'value'
hash.key?(:key)  # => true
hash.key?('key') # => true
Calls superclass method
# File lib/proper_properties/properties.rb, line 22
def key?(key)
  super(convert_key(key))
end
values_at(*indices) click to toggle source

Returns an array of the values at the specified indices:

hash = ProperProperties::Properties.new
hash[:a] = 'x'
hash[:b] = 'y'
hash.values_at('a', 'b') # => ["x", "y"]
# File lib/proper_properties/properties.rb, line 46
def values_at(*indices)
  indices.collect {|key| self[convert_key(key)]}
end

Protected Instance Methods

convert_key(key) click to toggle source
# File lib/proper_properties/properties.rb, line 60
  def convert_key(key)
    key.kind_of?(String) ? key.to_sym : key
end