Method | Saves to DB | Default Accessor | Validations | Callbacks | Touches updated_at | Readonly check |
---|---|---|---|---|---|---|
attribute= | ❌ | ✅ | ||||
write_attribute | ❌ | ❌ | ||||
update_attribute | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ |
attributes= | ❌ | ✅ | ||||
update | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
update_column | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ |
update_columns | ✅ |
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 Class | |
def new(...) | |
warn 'Overriding Class#new' | |
instance = allocate | |
instance.send(:initialize, ...) | |
instance | |
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
# frozen_string_literal: true | |
module Kernel | |
def Binary(string, exception: true) | |
hex = string.b | |
hex.gsub!(/#[^#]*$\R*/, '') | |
hex.gsub!(/"[^"]*"/) do |quotes| | |
quotes[1..-2].unpack1('H*') | |
end | |
hex.delete!("\s\t") |
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 StructLiteral | |
refine Hash do | |
def to_struct(class_name = nil) | |
if class_name | |
Object.const_set(class_name, Struct.new(*keys)) | |
Object.const_get(class_name).new(*values) | |
else | |
Struct.new(*keys).new(*values) | |
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
# frozen_string_literal: true | |
class RingBuffer | |
Nothing = Data.define | |
EMPTY = Nothing.new | |
attr_reader :size | |
def initialize(capacity:) | |
@capacity = capacity |
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
# frozen_string_literal: true | |
require 'curses' | |
require 'singleton' | |
module Isene | |
class ColorRegistry | |
include Singleton | |
attr_reader :colors |
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
## | |
# A non-root installation of the latest Ruby with chruby | |
# Install chruby (https://github.com/postmodern/chruby#readme) | |
mkdir -p $HOME/src | |
cd $HOME/src | |
wget -O chruby-0.3.9.tar.gz https://github.com/postmodern/chruby/archive/v0.3.9.tar.gz | |
tar -xzvf chruby-0.3.9.tar.gz | |
cd chruby-0.3.9/ | |
PREFIX=$HOME/.chruby make install |
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 'rubocop' | |
require 'tempfile' | |
class InlineRunner | |
DEFAULT = RuboCop::Runner.new({}, RuboCop::ConfigStore.new) | |
def initialize(runner: DEFAULT, filename: 'runner.rb') | |
@runner = runner | |
@file = Tempfile.new(filename) | |
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
require 'nokogiri' | |
url = 'http://zales.1.ai' | |
Nokogiri::HTML(`curl #{url}`).css('title').text |
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 arg = false | |
{arg: arg, block: block_given?} | |
end | |
end | |
class Bar < Foo | |
def foo *args | |
super | |
end |