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 'benchmark' | |
a = {foo: 'Hello'} | |
b = {bar: ' world'} | |
n = 100_000_000 | |
Benchmark.bm do |x| | |
x.report("{**a,**b}") do | |
n.times { | |
{**a, **b} |
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
RSpec::Matchers.define :permit do |action| | |
match do |object| | |
read_user object | |
permit?(action, user: @user, context: @object) | |
end | |
def read_user(object) | |
return if @user |
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 Pivilages | |
def load_privilages_for(user) | |
Authorization.current_user = user | |
file_name = File.join(Rails.root, 'config', 'authorization_rules.rb') | |
rules = File.read(file_name) | |
load_engine_analyzer_for rules | |
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 Foo | |
def foo(bar=nil) | |
@bar = (bar || @bar) | |
end | |
end | |
# Example | |
foo = Foo.new | |
foo.foo() # => nil | |
foo.foo(10) # => 10 |
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
# config/application.rb | |
module RailsApp | |
class Application < Rails::Application | |
# ... | |
files = File.join(Rails.root, 'app', 'models') + File::SEPARATOR + '*_observer.rb' | |
observers = [] | |
Dir[files].each do |file| | |
observers << File.basename(file).gsub('.rb','').to_sym | |
end |