This file contains hidden or 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 YOLO | |
| attr_reader :i, | |
| :want, | |
| :to, | |
| :die, | |
| def really | |
| :die | |
| end | |
| end |
This file contains hidden or 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 FakeHash | |
| def to_hash | |
| { a: 1, b: 2, c: 3 } | |
| end | |
| end | |
| class FakeArray | |
| def to_a | |
| [1, 2, 3] | |
| end |
This file contains hidden or 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 WrappedError | |
| def initialize(error) | |
| @error = error | |
| end | |
| def exception | |
| @error.exception | |
| end | |
| end |
This file contains hidden or 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
| puts "Ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}:\n" | |
| require 'benchmark/ips' | |
| def without_block(x,y,z); end | |
| def with_block(x,y,z,&b); end | |
| puts | |
| puts '* no passing a block' | |
| puts |
This file contains hidden or 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 | |
| puts "Ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}:\n" | |
| require 'benchmark/ips' | |
| puts | |
| puts '* #to_s:' | |
| puts |
This file contains hidden or 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 = { 'a' => :ok } | |
| p a.keys.first.frozen? # always true | |
| b = { 'a' => :ok } | |
| p a.keys.first.object_id | |
| p b.keys.first.object_id | |
| p a.keys.first.object_id == b.keys.first.object_id # false for < 2.1, true for >= 2.1 |
This file contains hidden or 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
| k = [1] | |
| h = {} | |
| h[k] = 1 | |
| k << 2 | |
| h[k] = 2 | |
| p h # {[1, 2]=>1, [1, 2]=>2} | |
| k = [1] | |
| h = {k => 1, (k << 2) => 2} |
This file contains hidden or 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
| h = { [] => :ok } | |
| p h[[]] # ok | |
| h = { [:lol] => :ok } | |
| p h[[:lol]] # ok | |
| h = { [] => :ok } | |
| h.first.first << :lol | |
| p h[[:lol]] # nil |
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| require 'open-uri' | |
| url = ARGV[0] | |
| $stderr.puts 'URL not specified' and exit 1 unless url | |
| uri = URI.parse url | |
| $stderr.puts 'This should be 9gag.com URL' and exit 1 if uri.host != '9gag.com' | |
| m = uri.path.match %r{^/gag/(\w+)$} | |
| $stderr.puts 'Malformed URL!' and exit 1 unless m |
This file contains hidden or 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
| # Online (non-blocking) ActiveRecord migrations using pt-online-schema-change utility from Percona Toolkit. | |
| # | |
| # In your Rails app put it as lib/online_change_table.rb | |
| # Now you can use it in your migration file: | |
| # | |
| # require 'online_change_table' | |
| # | |
| # class AddSomethingToSomethings < ActiveRecord::Migration | |
| # def up | |
| # online_change_table :somethings do |t| |