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 Temperature | |
include Comparable | |
attr_reader :degrees | |
COLD = 20 | |
HOT = 25 | |
def initialize(degrees) | |
@degrees = degrees | |
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 Product < ActiveRecord::Base | |
def cost | |
Money.new(cents, currency) | |
end | |
def cost=(cost) | |
self.cents = cost.cents | |
self.currency = cost.currency.to_s | |
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
> product = Product.create(cost: Money.new(500, "EUR")) | |
> product.cost | |
=> #<Money fractional:500 currency:EUR> | |
> product.cost.cents | |
=> 500 | |
> product.currency | |
=> "EUR" |
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 Event < ActiveRecord::Base | |
SIZE = %w( | |
small | |
medium | |
big | |
) | |
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 Size | |
SIZES = %w(small medium big) | |
attr_reader :size | |
def initialize(size) | |
@size = size | |
end | |
def self.to_select | |
SIZES.map{|c| [c.capitalize, c]} |
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
> event = Event.create(name: 'Ruby conf', start_date: Date.today, end_date: Date.today + 1.days) | |
> event.date_range | |
=> #<DateRange:0x007fd8760c2690 @start_date=Tue, 06 Jun 2017, @end_date=Fri, 07 Jun 2017> | |
> event.date_range.include_date?(Date.today) | |
=> true | |
> event.date_range.include_date_range?(DateRange.new(Date.today, Date.today + 2.days)) | |
=> false | |
> event.date_range.include_date_range?(DateRange.new(Date.today, Date.today + 1.days)) | |
=> 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
> room_1 = Room.create(degrees: 10) | |
> room_2 = Room.create(degrees: 20) | |
> room_3 = Room.create(degrees: 30) | |
> room_1.temperature.cold? | |
=> true | |
> room_1.temperature.hot? | |
=> false | |
> [room_1.temperature, Temperature.new(20), room_3.temperature, room_2.temperature].sort | |
=> [#<Temperature:0x007fe194378840 @degrees=10>, #<Temperature:0x007fe194378818 @degrees=20>, #<Temperature:0x007fe1943787c8 @degrees=20>, #<Temperature:0x007fe1943787f0 @degrees=30>] | |
> [room_1.temperature, Temperature.new(20), room_3.temperature, room_2.temperature].uniq |
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 DateRange < Value.new(:start_date, :end_date) | |
def include_date?(date) | |
date >= start_date && date <= end_date | |
end | |
def include_date_range?(date_range) | |
start_date <= date_range.start_date && end_date >= date_range.end_date | |
end | |
def overlap_date_range?(date_range) |
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
# Xcode Command-line Tools | |
xcode-select --install | |
# Productivity | |
brew install --cask rectangle | |
brew install notion | |
# Finder settings | |
# Show hidden files | |
defaults write com.apple.finder AppleShowAllFiles 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
export const ScreenshotTool = () => { | |
... | |
return ( | |
<Fragment> | |
<div> | |
<button disabled={canCapture} onClick={startImagePreview}> | |
Preview | |
</button> | |
<button disabled={!canCapture} onClick={captureImageInPreview}> |