https://www.leanpanda.com/blog/2016/04/11/smart-integration.testing/
Last active
December 10, 2016 18:59
-
-
Save dawilster/09145bf314a5f8547d7c28dccd97335b to your computer and use it in GitHub Desktop.
Ruby Snippets I Like
Initialization:
source: https://github.com/jekyll/classifier-reborn/blob/master/lib/classifier-reborn/bayes.rb#L21
def initialize(*args)
@categories = {}
options = { language: 'en',
auto_categorize: false,
enable_threshold: false,
threshold: 0.0,
enable_stemmer: true
}
args.flatten.each do |arg|
if arg.is_a?(Hash)
options.merge!(arg)
else
add_category(arg)
end
end
end
Let accepts params from later defined let blocks
Source: https://www.leanpanda.com/blog/2015/08/24/machine-learning-automatic-classification/
let(:command) { described_class.new(advertisements, training) }
let(:advertisements) { [build(:advertisement, title: 'foo')] }
let(:training) do
[
{ title: 'foo baz', category_id: 1 },
]
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment