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
# app/utils/calculator.rb | |
class StatelessCalculator | |
def self.add(x, y) | |
x + y | |
end | |
# ...subtract, divide, multiply, etc. | |
end | |
# app/services/calculation_isolate.rb |
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 RssImporter | |
attr_writer :articles | |
attr_reader :result | |
def import | |
@result = articles.map do |article| | |
RssContent.create { url: article.url, text: article.body } | |
end | |
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
# our first import | |
importer = RssImporter.new | |
importer.articles = a_bunch_of_rss_content | |
importer.import | |
imported = importer.result | |
# second import, same instance of RssImporter | |
importer.articles = other_rss_content | |
importer.result # same value as "imported" on line 5 |
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 RssImporter | |
def self.import(articles) | |
articles.map do |article| | |
RssContent.create { url: article.url, text: article.body } | |
end | |
end | |
end | |
# somewhere in your codebase... | |
imported = RssImporter.import a_bunch_of_rss_content |
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
# app/utils/calculator.rb | |
module StatelessCalculator | |
def add(x, y) | |
x + y | |
end | |
module_function :add | |
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
class AssetService | |
def prune_stale_images | |
Prunable.from_assets(Image.all).each do |image| | |
S3Object.delete image.s3_object_name, image.s3_bucket_name | |
image.destroy | |
end | |
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
class AssetService | |
def prune_stale_images | |
--hard_coded_return_value--.each do |image| | |
S3Object.delete image.s3_object_name, image.s3_bucket_name | |
image.destroy | |
end | |
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
x = { | |
createCheckbox: function (o) { | |
var t = ''; | |
t += '<label class="checkbox {{class}}">'; | |
t += helpers.viewUtil.createBareCheckbox(o); | |
t += '</label>'; | |
return Mustache.to_html(t, o); | |
}, | |
createBareCheckbox: function (o) { |
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
# in some shared file | |
SomeNamespace.isZipInState = (zip, state) -> | |
ranges = STATE_RANGES[state] | |
return true if ! ranges? || ! zip | |
zip = value.match(/^\D*(\d\D*){5}/)[0] | |
zip = parseInt zip.replace(/\D/g,'') if zip | |
return true if ! zip | |
results = [] | |
for range in ranges | |
do (range) -> |
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
require 'active_record' | |
require 'barrister' | |
require 'pry' | |
require 'redis' | |
require 'erb' | |
# App | |
require './models.rb' | |
require './service.rb' |