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
# Only use self when it is necessary. | |
# reader methods do not require self unless a local variable is declared with the same name (which is a bad idea anyway) | |
# setter methods do require self, otherwise you are creating a local variable | |
# Minimal use of self (only writes use 'self') | |
class Person | |
attr_accessor :name, :date_of_birth | |
def initialize(name:, date_of_birth:) |
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
# Boolean paramters easily lose their context/meaning. Ex. car.drive(true) # what is true? | |
# | |
# (1) If you have booleans, use named args. | |
# (2) If you dont have named args, use an options hash with fetch. | |
# (3) At the very worse, have the method take a meaningful string/symbol and determing truthiness from the passed value. | |
# BAD. Hard to tell what the boolean means when calling the method. | |
# | |
# load_video('kitty-yawn.mp4', true) |
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
# attr_reader methods | |
# √ 1 common way to access attribute value | |
# √ Easier to refactor into a calculated/facade attribute | |
# attr_reader methods | |
class Person | |
attr_reader :name, :date_of_birth | |
def initialize(name:, date_of_birth:) |
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
# Memoized facade attribute | |
# √ Lazy loaded | |
# √ Better encapsulated / more 'atomic'. Processing introduces unnecessary depencies at different times of the life cycle of the object. | |
# √ More idiomatic mindset to think of these are 'attributes' on an object, than results of a calculation | |
# Memoized attribute | |
class RecommendationCalculator | |
attr_reader :user | |
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
#upload_target { | |
display:none ! important; | |
} | |
div.bottom { | |
padding:0px ! important; | |
margin:0px ! important; | |
background-image: none ! important; | |
} | |
div#last_message{ | |
display:none ! important; |
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
context ".rent book with quantity" do | |
setup do | |
@book = Factory(:book, :quantity => 1) | |
@customer = Factory(:customer) | |
end | |
execute do | |
@customer.rent(@book) | |
end | |