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 flatten(array) | |
array.reduce([]) do |sum, n| | |
sum + (n.kind_of?(Array) ? flatten(n) :[n]) | |
end | |
end | |
p flatten([[1,2,[3]],4]) |
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
module FormObjectHelpers | |
extend ActiveSupport::Concern | |
included do | |
def form(klass, attributes = {}, options = {}) | |
form = klass.new(current_user, params, attributes) | |
authorize_model(form, options) | |
yield form if block_given? | |
render action_name, locals: { form: form } |
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
require 'ostruct' | |
class BaseForm | |
include ActiveModel::Model | |
attr_reader :attributes, | |
:attributes_hash, | |
:current_user, | |
:params, | |
:params_hash, | |
:model |
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
cloc . --exclude-dir=node_modules,tmp,webpack,vendor,cookbooks,public,log |