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 Employee | |
attr_writer :salary | |
attr_reader :salary | |
def initialize name, salary | |
@name = name | |
@salary = salary | |
end | |
end | |
employee = Employee.new("Homer", 500) |
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 Employee | |
def initialize name, salary | |
@name = name | |
@salary = salary | |
end | |
def salary | |
return salary | |
end | |
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
# 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, |
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
# 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] |
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 Invoice | |
def initialize *lines | |
@lines = lines | |
end | |
def total | |
@lines.inject(0){ |subtotal, line| subtotal += line.total } | |
end | |
end |
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 Invoice | |
def initialize *lines | |
@lines = lines | |
end | |
def total | |
@lines.inject(0){ |subtotal, line| subtotal += line_subtotal(line) } | |
end | |
def line_subtotal line |
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 Example | |
def initialize(headquarters, positions) | |
@positions = positions | |
@headquarters = headquarters | |
end | |
def open_headquarter(headquarter) | |
@headquarters[headquarter] = [] | |
end |
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 Company | |
def open_headquarter headquarter | |
@headquarters << headquarter | |
end | |
def close_headquarter(headquarter_name) | |
@headquarters.delete_if{ |headquater| headquarter.name == headquarter_name } | |
end | |
end |
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 User | |
def initialize name, user_information={} | |
@name = name | |
@phone_number = user_information[:phone_number] | |
end | |
def name | |
return @name | |
end |
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 User | |
def initialize(name, user_information={}) | |
@name = name | |
@phone_number = user_information[:phone_number] || NullPhoneNumber.new | |
end | |
def name | |
@name | |
end |
OlderNewer