Skip to content

Instantly share code, notes, and snippets.

View BrayanZ's full-sized avatar

Brayan BrayanZ

  • 09:08 (UTC -06:00)
View GitHub Profile
class Employee
attr_writer :salary
attr_reader :salary
def initialize name, salary
@name = name
@salary = salary
end
end
employee = Employee.new("Homer", 500)
class Employee
def initialize name, salary
@name = name
@salary = salary
end
def salary
return salary
end
# CommentsController handles model and view for Comment, and Review. It determines the types of
# of the comment resource (Post or Kata) and the comment (Comment or Review) by parsing the html
# request path.
class CommentsController < ApplicationController
before_filter :authenticate_user!, :load_commentable, :load_commentable_collection
before_filter :select_comment_symbol, :only => [:create, :update]
##
# Create a new comment that belongs to a user and a post,
# 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]
class Invoice
def initialize *lines
@lines = lines
end
def total
@lines.inject(0){ |subtotal, line| subtotal += line.total }
end
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 Example
def initialize(headquarters, positions)
@positions = positions
@headquarters = headquarters
end
def open_headquarter(headquarter)
@headquarters[headquarter] = []
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 User
def initialize name, user_information={}
@name = name
@phone_number = user_information[:phone_number]
end
def name
return @name
end
class User
def initialize(name, user_information={})
@name = name
@phone_number = user_information[:phone_number] || NullPhoneNumber.new
end
def name
@name
end