Class: Utopia::Content::SymbolicHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/utopia/content/markup.rb

Overview

A hash which forces all keys to be symbols and fails with KeyError when strings are used.

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

Fetch a value using a symbolic key.

Raises:

  • (KeyError)


21
22
23
24
# File 'lib/utopia/content/markup.rb', line 21

def [] key
	raise KeyError.new("attribute #{key} is a string, prefer a symbol") if key.is_a? String
	super key.to_sym
end

#[]=(key, value) ⇒ Object

Assign a value after coercing its key to a symbol.



30
31
32
# File 'lib/utopia/content/markup.rb', line 30

def []= key, value
	super key.to_sym, value
end

#fetch(key, *arguments, &block) ⇒ Object

Fetch a value after coercing the key to a symbol.



39
40
41
42
43
# File 'lib/utopia/content/markup.rb', line 39

def fetch(key, *arguments, &block)
	key = key.to_sym
	
	super
end

#include?(key) ⇒ Boolean

Check whether this collection includes the given value.

Returns:

  • (Boolean)


48
49
50
51
52
# File 'lib/utopia/content/markup.rb', line 48

def include? key
	key = key.to_sym
	
	super
end