Class: ECS::Operations

Inherits:
Object
  • Object
show all
Defined in:
lib/ecs/operations.rb

Direct Known Subclasses

ResponseGroups

Constant Summary collapse

@@klasses =
{}

Class Method Summary collapse

Class Method Details

.[](ideal) ⇒ Object



17
18
19
20
# File 'lib/ecs/operations.rb', line 17

def self.[]( ideal )
  self.clear unless @@klasses.is_a?( Hash )
  @@klasses[( ideal.is_a?( Class ) ? ideal.name : ideal.to_s ).to_sym]
end

.[]=(ideal, actual) ⇒ Object



12
13
14
15
# File 'lib/ecs/operations.rb', line 12

def self.[]=( ideal, actual )
  self.clear unless @@klasses.is_a?( Hash )
  @@klasses[( ideal.is_a?( Class ) ? ideal.name : ideal.to_s ).to_sym] = actual.is_a?( Class ) ? actual : actual.class
end

.clearObject



8
9
10
# File 'lib/ecs/operations.rb', line 8

def self.clear
  @@klasses = {}
end

.method_missing(meth, *args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ecs/operations.rb', line 22

def self.method_missing( meth, *args )
  #You can send anything to ECS::Operations that you can send to a hash
  #If there is a conflict between the hash's (@@klasses) method name and
  #the ECS::Operations module's method name, you can call the method with o_ prepended
  #
  # E.G.
  #
  # ECS::Operations.include?( something ) # => calls the include? method on ECS::Operations
  # ECS::Operations.o_include?( something ) # => calls the include? method on the @@klasses class variable
  @@klasses = {} unless @@klasses.is_a?( Hash )
  if meth == :each
    @@klasses.each { |ideal,actual| yield( ideal, actual ) }
  else
    @@klasses.send( (meth.to_s =~ /^o_(.*)/ ? $1.to_sym : meth), *args )
  end
end