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
config.assets.paths += [ | |
Rails.root.join('vendor', 'assets', 'fonts') | |
] | |
config.assets.precompile += [ | |
'icons.eot', | |
'icons.svg', | |
'icons.ttf', | |
'icons.woff' | |
] |
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
# Concrete Strategy | |
class GrilledChickenStuffing | |
def cook | |
stuffing = [] | |
stuffing << 'sliced tomato' | |
stuffing << 'lettuce' | |
stuffing << 'grilled chicken breast' | |
stuffing | |
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 GrilledChicken | |
def cook | |
stuffing = [] | |
stuffing << 'sliced tomato' | |
stuffing << 'lettuce' | |
stuffing << 'grilled chicken' | |
stuffing | |
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 Burger | |
attr_reader :top_bun, :bottom_bun | |
attr_accessor :stuffing | |
def initialize(stuffing) | |
@top_bun = TOP_BUN | |
@stuffing = stuffing | |
@bottom_bun = BOTTOM_BUN | |
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
chicken_burger | |
= Burger.new(GrilledChicken.new) | |
cheese_burger | |
= Burger.new(BeefPatty.new) |
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
# Code Block | |
#1. {} Mostly used as a one-liner | |
{ puts 'Hi' } | |
#2. do end | |
do | |
puts 'Hi' | |
end | |
# example: arguments are wrapped between || | |
[1, 2].map {|num| num * 2} |
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
times_2 = Proc.new { |num| num * 2 } | |
times_2.call(3) # returns 6 | |
times_2 = proc { |num| num * 2 } | |
times_2.call(3) # returns 6 | |
times_2 = lambda { |num| num * 2 } | |
times_2.call(3) # returns 6 | |
times_2 = -> (num) { num * 2 } |
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
def burger | |
puts 'top bun' | |
yield if block_given? | |
puts 'bottom bun' | |
end | |
burger do | |
puts 'lettuce' | |
puts 'tomato' | |
puts 'chicken breast' |
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
# Example: passing arguments | |
def ten_plus | |
puts 'before yield' | |
yield(10) | |
puts 'after yield' | |
end | |
ten_plus do |num| | |
puts(num + 100) | |
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
# Passing a proc into a method | |
def give_me_a_proc(pr) | |
puts 'Before call the proc' | |
pr.call | |
puts 'After calling the proc' | |
end | |
noisy_proc = proc { puts 'Noisy' } | |
give_me_a_proc(noisy_proc) |
OlderNewer