Module: Intrinsic

Defined in:
lib/intrinsic.rb,
lib/intrinsic/version.rb,
lib/intrinsic/extrinsicism.rb,
lib/intrinsic/intrinsicism.rb,
lib/intrinsic/intrinsicism/coercion/hash.rb,
lib/intrinsic/intrinsicism/coercion/proc.rb,
lib/intrinsic/intrinsicism/coercion/array.rb,
lib/intrinsic/intrinsicism/coercion/string.rb,
lib/intrinsic/intrinsicism/coercion/symbol.rb,
lib/intrinsic/intrinsicism/coercion/integer.rb

Overview

The Intrinsic model is the gateway to all the sub models, and by including it into a model or class you gain all of the power of the library

Defined Under Namespace

Modules: Extrinsicism, Intrinsicism

Constant Summary collapse

VERSION =
"1.2.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(subject) ⇒ Object

Defines a hooks onto ‘include` so that the subject is also extended with the model meaning that singleton and instance methods exist on the class and instance of the class.



12
13
14
15
16
17
18
19
20
# File 'lib/intrinsic.rb', line 12

def self.included(subject)
  # Make a call to the superclass original included method
  super
  # Extend the class with the model to get the singleton methods
  subject.extend Intrinsicism
  # Send the include method with the model as an argument
  # TODO: Find out if this is needed?
  subject.send :include, Intrinsicism
end

Instance Method Details

#initialize(values = {}) ⇒ Object

Defines the initialize method that takes a hash and sets the properties to those values. It also takes the defaults and assigns them to the properties. TODO: Rename the parameter to something else, like ‘initial_properties` TODO: Make sure all the keys are symbols, or at least turn them into symbols



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/intrinsic.rb', line 26

def initialize(values = {})
  # Create a new empty table for the properties, and then merge in the defaults
  # TODO: Make defaults a class variable
  @properties = {}.merge self.class.defaults
  # Check to make sure all of the given properties are within the acceptable list
  # TODO: Rename this method, it's terribly named
  # TODO: Move it above everything else, and in an if block to save CPU time
  check_properties_of values
  # Go over each property-value pair and send the value to the correct
  # property method
  values.each { |property, value| send property.to_sym, value }
  # Return the object for chaining purposes
  # TODO: Is this even needed?
  self
end

#to_sObject

Redefining the ‘to_s` method so that print out is prettier TODO: Change object_id to the correct hash TODO: Remove self from object_id



45
46
47
# File 'lib/intrinsic.rb', line 45

def to_s
  "#<#{self.class}:#{self.object_id} #{properties.map{|k,v| k.to_s + '=' + v.inspect}.join(', ')}>"
end