Created
April 6, 2012 15:19
-
-
Save rsgrafx/2320717 to your computer and use it in GitHub Desktop.
Is this Good Practice? Storing in outside Objects accessed by a constant.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
OUTSIDE_STATE = true | |
NAMES = {:objects => []} | |
module CheckSelf | |
module ClassMethods | |
def self.inherited(child) | |
::NAMES[:objects] << child | |
end | |
def select_and_make_calls | |
_selected = NAMES[:objects].select {|child| | |
child.purpose() | |
}.each {|child| | |
# _child = child.new(child) | |
child.new(child).call_out | |
} | |
end | |
end | |
module InstanceMethods | |
def call_out | |
puts "FIRING OFF THE CALLS #{self.class}" | |
end | |
end | |
def self.included(receiver) | |
receiver.extend ClassMethods | |
receiver.send :include, InstanceMethods | |
end | |
end | |
class Parent | |
def initialize(name) | |
@name = name | |
end | |
include CheckSelf | |
# The inherited class must be defined in the * | |
# Body of the class. | |
def self.inherited(child) | |
NAMES[:objects] << child | |
end | |
end | |
class ObjectOne < Parent | |
def self.purpose | |
OUTSIDE_STATE | |
end | |
end | |
class ObjectTwo < Parent | |
def self.purpose | |
true | |
end | |
end | |
Parent.select_and_make_calls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment