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 'delegate' | |
require 'benchmark' | |
class User | |
attr_reader :name | |
def initialize(name) | |
@name = name | |
end | |
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 CreateUserForm | |
include ActiveModel::Model | |
attr_accessor :email | |
attr_accessor :name | |
def initialize | |
@user = User.new | |
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 Publisher | |
extend self | |
# delegate to ActiveSupport::Notifications.instrument | |
def broadcast_event(event_name, payload={}) | |
if block_given? | |
ActiveSupport::Notifications.instrument(event_name, payload) do | |
yield | |
end | |
else |
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 << true | |
def !@ | |
true | |
end | |
end | |
class << false | |
def !@ | |
false | |
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 Object | |
def raise_not_implemented | |
raise NotImplementedError.new("Define ##{caller_locations(1,1)[0].label} for #{self.class}") | |
end | |
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 Company < AR | |
has_many :users | |
has_many :discounts | |
end | |
class User < AR | |
belongs_to :company | |
has_many :discounts | |
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
>>> c = [1,2,[1,2]] | |
1,2,1,2 | |
>>> c.sort() | |
1,1,2,2 | |
>>> c.join('--') | |
1--1,2--2 | |
>>> c.length | |
3 | |
>>> c[0] | |
1 |
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
var a = 10; | |
function test() { | |
console.log(a); | |
var a = 100; | |
console.log(a); | |
}; | |
test(); |
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
# app/models/base.rb | |
module Base | |
def some_method | |
ImpClass.test | |
end | |
end | |
# app/models/impl_class | |
class ImlClass | |
include Base |
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.configure do |config| | |
config.around(:all, callbacks: true) do |example| | |
ActiveRecord::Base.skip_callbacks = false | |
example.run | |
ActiveRecord::Base.skip_callbacks = true | |
end | |
end | |
ActiveRecord::Base.skip_callbacks = true |