Module: Gather

Includes:
Enumerable
Included in:
Changes
Defined in:
lib/gather.rb

Overview

Provides instance method gather and class method property Allows properties to be Enumerable.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



53
54
55
# File 'lib/gather.rb', line 53

def self.included( base )
  base.extend( ClassMethods )
end

Instance Method Details

#[](symbol) ⇒ Object



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

def []( symbol )
  send( symbol )
end

#[]=(symbol, value) ⇒ Object



44
45
46
# File 'lib/gather.rb', line 44

def []=( symbol, value )
  send( symbol, value )
end

#each(&block) ⇒ Object



48
49
50
# File 'lib/gather.rb', line 48

def each( &block )
  self.class.properties.each( &block )
end

#gather(args = {}, &block) ⇒ Object

Evaluate the block and gather options from args. Even if it’s nil. Return self



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gather.rb', line 8

def gather( args = {}, &block )
  unless args.nil?
    args.each do |key,value|
      self.send( key, value )
    end
  end
  
  unless block.nil?
    if block.arity == -1
      instance_eval &block
    else
      yield self
    end
  end
  self
end

#merge(hash) ⇒ Object

return a new hash merged with the argument



36
37
38
# File 'lib/gather.rb', line 36

def merge( hash )
  to_hash.merge( hash )
end

#merge!(hash) ⇒ Object

set all values specified in the hash



31
32
33
# File 'lib/gather.rb', line 31

def merge!( hash )
  hash.each {|k,v| send( k, v ) }
end

#to_hash(properties = self.class.properties) ⇒ Object

return a hash of the properties



26
27
28
# File 'lib/gather.rb', line 26

def to_hash( properties = self.class.properties )
  properties.inject({}) {|s,x| s[x] = send(x); s}
end