Sha256: 1a35a4da1f97b48a0bd660b3f796295725c41e62ebbfa6eab63ee475b930e41c
Contents?: true
Size: 1.04 KB
Versions: 2
Compression:
Stored size: 1.04 KB
Contents
class CodeLabs::Lab # A single Lab on the page # # Example: # CodeLabs::Lab.new # or # CodeLabs::Lab.new(args) # # Arguments: # title, duration, link, author, last_updated attr_accessor :title, :duration, :link, :author, :last_updated def initialize(arguments={}) # default values @duration = "N/A" @author = "N/A" @techs = [] # Mass assignment arguments.each {|key, value| self.send("#{key}=", value) unless value == "" || value.nil?} # <- do not set the values if they are blank end def techs @techs.dup.freeze # <- freeze so we keep type integrity end def add_tech(tech) # <- enforce type and relationships raise TypeError unless tech.is_a?(CodeLabs::Tech) @techs << tech tech.add_lab(self) unless tech.labs.include?(self) # <- potenial infinte loop end def print_techs @techs.collect{|tech| tech.name}.join(', ') # <- Show all the related techs end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
code_labs-0.2.0 | lib/code_labs/lab.rb |
code_labs-0.1.0 | lib/code_labs/lab.rb |