Class: Herpes::Event

Inherits:
Object show all
Defined in:
lib/herpes/event.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Event

Returns a new instance of Event.



14
15
16
17
18
# File 'lib/herpes/event.rb', line 14

def initialize (&block)
	@data = {}
	
	instance_eval &block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id, *args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/herpes/event.rb', line 20

def method_missing (id, *args)
	id = id.to_s.sub(/[=?]$/, '').to_sym

	if args.length == 0
		@data[id]
	else
		if respond_to? "#{id}="
			send "#{id}=", *args
		else
			value = (args.length > 1) ? args : args.first

			if value.nil?
				@data.delete(id)
			else
				@data[id] = value
			end
		end
	end
end

Instance Method Details

#to_hashObject



40
41
42
# File 'lib/herpes/event.rb', line 40

def to_hash
	@data.dup
end