Skip to content
This repository has been archived by the owner on Mar 4, 2018. It is now read-only.

Commit

Permalink
Documenting the initialize method provided to objects
Browse files Browse the repository at this point in the history
  • Loading branch information
krainboltgreene authored and Kurtis Rainbolt-Greene committed Jan 8, 2012
1 parent d510a9f commit b3dfe9c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/intrinsic.rb
Expand Up @@ -18,10 +18,17 @@ def self.included(subject)
subject.send :include, Intrinsicism
end

# 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.
def initialize(values = {})
# Create a new empty table for the properties, and then merge in the defaults
@properties = {}.merge self.class.defaults
# Check to make sure all of the given properties are within the acceptable list
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
self
end

Expand Down

0 comments on commit b3dfe9c

Please sign in to comment.