Last active
August 29, 2015 14:08
-
-
Save Lukom/c11fdee599bac51fe2fa to your computer and use it in GitHub Desktop.
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
class Human | |
attr_reader :name, :amount | |
def initialize(name, amount) | |
@name = name | |
@amount = amount | |
end | |
def deposit(amount) | |
@amount += amount | |
end | |
def withdraw(amount) | |
@amount -= amount | |
end | |
def say(text) | |
puts text | |
end | |
end | |
# ParentExtension.rb | |
class Human | |
def parent_give_pocket_money_to(child) | |
amount = 5 # five backs | |
withdraw(amount) | |
child.receive_pocket_money(amount) | |
end | |
end | |
# ChildExtension.rb | |
class Human | |
def child_receive_pocket_money(amount) | |
deposit(amount) | |
say('Thank you') | |
end | |
end | |
# EmployeeExtension.rb | |
class Human | |
def employee_receive_salary(amount) | |
deposit(amount) | |
... | |
end | |
def employee_do_job_task() | |
... | |
end | |
end | |
# ParentingController.rb | |
class ParentingController < ApplicationController | |
def do_parenting | |
child = Human.find params[:id] | |
current_user.parent_give_pocket_money_to child | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment