Skip to content

Instantly share code, notes, and snippets.

@Lukom
Last active August 29, 2015 14:08
Show Gist options
  • Save Lukom/c11fdee599bac51fe2fa to your computer and use it in GitHub Desktop.
Save Lukom/c11fdee599bac51fe2fa to your computer and use it in GitHub Desktop.
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