Class: Shaddox::Settings

Inherits:
Hash
  • Object
show all
Defined in:
lib/shaddox/settings.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/shaddox/settings.rb', line 3

def method_missing(meth, *args, &blk)
	name = meth.to_s

	return evaluate(self[meth])  if name.size == 1

	# Ruby 1.8.7 doesn't let you do string[-1]
	key, suffix = name[0..-2].to_sym, name[-1..-1]

	case suffix
	when '='
		self[key] = args.first
	when '?'
		include? key
	when '!'
		raise Error, "Setting :#{key} is not set" unless include?(key)
		evaluate self[key]
	else
		evaluate self[meth]
	end
end

Instance Method Details

#evaluate(value) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/shaddox/settings.rb', line 24

def evaluate(value)
	if value.is_a?(Proc)
		value.call
	else
		value
	end
end