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
/*** Custom RArray class ***/ | |
class RArray extends Array { | |
// Returns an array containing the items for which the given closure is not true. | |
reject (callback) { | |
return this.filter((val) => { | |
return !callback(val); | |
}); | |
} |
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
# Imagining a case where you are using loads of conditionals to show different parts of UI. | |
# There are 2 solutions of what can I see at the moment, either you are creating a different | |
# view either you fill your view with conditionals. | |
# index.html.erb - This would be the example where you fill your view with loads of conditionals | |
<div> | |
<% if can? :delete, :users %> | |
<button id="delete_selected">Delete selected</button> | |
<% 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
module SelectOptions | |
extend ActiveSupport::Concern | |
FIRST_OPTION = %w[All default].freeze | |
class_methods do | |
def enum_select_options(enum_name) | |
define_singleton_method "#{enum_name}_select_options" do |method_params = { header: true }| | |
map = send(enum_name.to_s.pluralize).map { |k, _| [k.humanize, k]} |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |