Skip to content

Instantly share code, notes, and snippets.

@djbender
Created September 9, 2013 18:39
Show Gist options
  • Save djbender/6499724 to your computer and use it in GitHub Desktop.
Save djbender/6499724 to your computer and use it in GitHub Desktop.
class Employee
attr_accessor :title, :name
def initialize(employee_attributes)
@title = employee_attributes[:title]
@name = employee_attributes[:name]
end
end
class Manager < Employee
def hours
40
end
end
class Programmer < Employee
def hours
80
end
end
class Thank
def generate(employee_attributes)
employee = EmployeeFactory.new_employee(employee_attributes)
"Thank you #{employee.name} for your #{employee.hours} hours of hard work!"
end
end
class EmployeeFactory
def self.new_employee(employee_attributes)
employee_attributes.title.constantize.new(employee_attributes)
end
end
@skatenerd
Copy link

Thanks for the feedback :-)

I think this only works in Rails.

In the blog, I was trying to make observations about OO in general; I just happened to be using Ruby.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment