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
Classes: UniqueArray
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
102
103
104
|
# File 'lib/gather.rb', line 102
def self.included( base )
base.extend( ClassMethods )
end
|
Instance Method Details
#[](symbol) ⇒ Object
89
90
91
|
# File 'lib/gather.rb', line 89
def []( symbol )
send( symbol )
end
|
#[]=(symbol, value) ⇒ Object
93
94
95
|
# File 'lib/gather.rb', line 93
def []=( symbol, value )
send( symbol, value )
end
|
#each(&block) ⇒ Object
97
98
99
|
# File 'lib/gather.rb', line 97
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/gather.rb', line 42
def gather( args = {}, &block )
unless args.nil?
args.each do |key,value|
self.send( key, value )
end
end
unless block.nil?
if RUBY_VERSION && RUBY_VERSION >= '1.9.0' && block.arity == 0
instance_eval( &block )
elsif block.arity == -1
instance_eval( &block )
else
yield self
end
end
self
end
|
#merge(hash) ⇒ Object
return a new hash merged with the argument
85
86
87
|
# File 'lib/gather.rb', line 85
def merge( hash )
to_hash.merge( hash )
end
|
#merge!(hash) ⇒ Object
set all values specified in the hash
76
77
78
|
# File 'lib/gather.rb', line 76
def merge!( hash )
hash.each {|k,v| send( k, v ) }
end
|
#properties ⇒ Object
61
62
63
|
# File 'lib/gather.rb', line 61
def properties
self.class.properties
end
|
#start=(value) ⇒ Object
80
81
82
|
# File 'lib/gather.rb', line 80
def start=( value )
Time.new( value.to_n * 60 * 60 )
end
|
#to_a(properties = self.class.properties) ⇒ Object
Also known as:
values
70
71
72
|
# File 'lib/gather.rb', line 70
def to_a( properties = self.class.properties )
properties.inject([]) {|s,x| s << send(x) }
end
|
#to_hash(properties = self.class.properties) ⇒ Object
return a hash of the properties
66
67
68
|
# File 'lib/gather.rb', line 66
def to_hash( properties = self.class.properties )
properties.inject({}) {|s,x| s[x] = send(x); s}
end
|