Skip to content

Instantly share code, notes, and snippets.

View BrayanZ's full-sized avatar

Brayan BrayanZ

  • 08:34 (UTC -06:00)
View GitHub Profile
class Notification
def initialze(kind, body)
@kind, @body = kind, body
end
def send_sms_notification
# sends a sms notification
end
def send_email_notification
class Employee
def initialize(name, base_salary)
@name = name
@base_salary = base_salary
end
def calculate_net_salary
# business logic about how to calculate the net salary
end
end
class Employee
def initialize(name, base_salary)
@name = name
@base_salary = base_salary
end
def calculate_net_salary
# business logic about how to calculate the net salary
end
class User
def initialize(name, user_information={})
@name = name
@phone_number = user_information[:phone_number] || NullPhoneNumber.new
end
def name
@name
end
class User
def initialize name, user_information={}
@name = name
@phone_number = user_information[:phone_number]
end
def name
return @name
end
class Company
def open_headquarter headquarter
@headquarters << headquarter
end
def close_headquarter(headquarter_name)
@headquarters.delete_if{ |headquater| headquarter.name == headquarter_name }
end
end
class Example
def initialize(headquarters, positions)
@positions = positions
@headquarters = headquarters
end
def open_headquarter(headquarter)
@headquarters[headquarter] = []
end
class Invoice
def initialize *lines
@lines = lines
end
def total
@lines.inject(0){ |subtotal, line| subtotal += line_subtotal(line) }
end
def line_subtotal line
class Invoice
def initialize *lines
@lines = lines
end
def total
@lines.inject(0){ |subtotal, line| subtotal += line.total }
end
end
# Update the attributes of a post/article/kata, and generate a notice if the changes could
# be saved or retry to edit otherwise.
# The attributes to be saved are different between Post and Kata.
# For Post, tags and source url need to be saved.
# For Kata, categories, challenge level and source url need to be saved.
def update
@post = post_type.find_by_slug(params[:id])
authorize! :update, @post
@form = params[@type.downcase.to_sym]