This file contains hidden or 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
AllCops: | |
Exclude: | |
- bin/**/* | |
- db/**/* | |
- vendor/**/* | |
Rails: | |
Enabled: true | |
# Disables "Use nested module/class definitions instead of compact style" warning |
This file contains hidden or 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
# A Node to be used within a LinkedList | |
class Node | |
attr_accessor :payload, :next_node | |
def initialize(payload, next_node = nil) | |
@payload = payload | |
@next_node = next_node | |
end | |
def to_s |
This file contains hidden or 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 Pawn < Piece | |
def first_move?(y) | |
#Allowed to move 1 or 2 spaces. | |
if (color: :white && y_position: 1) || (color: :black && y_position: 6) | |
return true | |
if (y_position - y) < 3 | |
else | |
return false | |
end | |
end |
This file contains hidden or 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
# Run this in a console. | |
(0..100).map do |number| | |
x = "foo" | |
p x.object_id | |
end | |
# Then run this | |
(0..100).map do |number| | |
x = "foo".freeze | |
p x.object_id |
This file contains hidden or 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
# Old 😞 | |
Post.preload(:user, :category, comments: { user: :avatar }).where(something: true).limit(100) | |
# New & Improved 😎 | |
Post.with_preloads.where(something: true).limit(100) |
This file contains hidden or 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
scope :with_preloads, -> { preload preload_attributes } | |
class << self | |
def preload_attributes | |
[:user, :category, comments: { user: :avatar }] | |
end | |
end |
This file contains hidden or 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
Post.preload(:user, :category, comments: { user: :avatar }).where(something: true).limit(100) |
This file contains hidden or 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
output = "1234\n" \ | |
"5467\n" \ | |
"more!" |