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 'sequel/model' | |
module Sequel | |
class << self | |
# abstract model needs to avoid inherited callback | |
# (see https://groups.google.com/forum/#!msg/sequel-talk/OG5ti9JAJIE/p1iqO57cwqwJ) | |
# MyAbstractModel = Sequel.new_abstract_model do | |
# # ... your common stuff ... |
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 'active_support' | |
require 'active_support/concern' | |
require 'active_support/core_ext' | |
require 'active_support/json' | |
# String#to_json to escape any string outside BMP | |
module StringToJsonWithEscape4byteUtf8 | |
extend ActiveSupport::Concern | |
included do |
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 TwoPlusTwoIsFive | |
def self.included(base) | |
base.class_exec do | |
alias_method :plus_without_two_plus_two_is_five, :+ | |
private :plus_without_two_plus_two_is_five | |
alias_method :+, :plus_with_two_plus_two_is_five | |
public :+ | |
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
# for Rails 3.2.12 | |
# loads fixtures a lot faster | |
require 'active_record/fixtures' | |
class ActiveRecord::Fixtures | |
# based on activerecord-3.2.12/lib/active_record/fixtures.rb l.462 | |
# modified lines are marked CHANGED | |
def self.create_fixtures(fixtures_directory, table_names, class_names = {}) | |
table_names = [table_names].flatten.map { |n| n.to_s } |
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 MaybeClass < DelegateClass(FalseClass) | |
LIKELIHOOD = 0.4 | |
def initialize | |
super(rand < LIKELIHOOD) | |
end | |
def ==(obj) | |
obj.class == self.class |
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
# coding: utf-8 | |
require 'sequel/adapters/sqlite' | |
# monkey patch to optionally open database in read-only mode | |
class ::Sequel::SQLite::Database | |
# [Copied] from sequel-4.5.0/lib/sequel/adapters/sqlite.rb | |
def connect(server) | |
opts = server_opts(server) |
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 Enumerable | |
def self.product(first, *rest) | |
return enum_for(__method__, first, *rest) unless block_given? | |
if rest.empty? | |
first.each do |v0| | |
yield [v0] | |
end | |
else | |
enum_for_rest = product(*rest) |
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 Sequel | |
module Plugins | |
module AssociationExists | |
module DatasetMethods | |
def association_exists(association, &block) | |
_association_exists(association, &block) | |
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 Rubinius | |
config = {} | |
config[:config_file] = "/Users/ippei/src/rubinius-3.33/config.rb" | |
config[:command_line] = ["--prefix=/Users/ippei/.rvm/rubies/rbx-3.33", "--with-opt-dir=/usr/local/opt/openssl:/usr/local/opt/readline:/usr/local/opt/libyaml:/usr/local/opt/gdbm", "--llvm-path=/usr/local/Cellar/llvm/3.6.2"] | |
config[:build_make] = "make" | |
config[:build_rake] = "rake" | |
config[:build_perl] = "perl" | |
config[:llvm_path] = "/usr/local/Cellar/llvm/3.6.2" | |
config[:llvm_system_name] = nil | |
config[:llvm_configure] = "/usr/local/opt/llvm/bin/llvm-config" |
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
$ irb | |
irb(main):001:0> class Fixnum | |
irb(main):002:1> def plus_with_two_plus_two_is_five(other) | |
irb(main):003:2> other += 1 if self == 2 && other == 2 | |
irb(main):004:2> plus_without_two_plus_two_is_five(other) | |
irb(main):005:2> end | |
irb(main):006:1> alias_method :plus_without_two_plus_two_is_five, :+ | |
irb(main):007:1> alias_method :+, :plus_with_two_plus_two_is_five | |
irb(main):008:1> end | |
Rubinius::InvalidBytecode: instruction argument is not a Fixnum: code: call, ip: 13 |