Skip to content

Instantly share code, notes, and snippets.

@dimameshcharakou
dimameshcharakou / hash_fetch_vs_block_with_no_argument.rb
Last active August 7, 2017 09:37
hash fetch default vs block with no argument
require 'benchmark'
Benchmark.bm do |x|
x.report("fetch with block") do
1_000_000.times do
attrs = {}
attrs.fetch('xyz') { 'abc' }
end
end
# uploads and retrieves route data to/from OpenStack Swift
class SwiftRouteUpload
RC_ROUTES = 'runningcoach_routes'.freeze
AUTH_METHOD = 'password'.freeze
AUTH_URL = 'https://cloudstorage.flow.ch/auth/v1.0'.freeze
SERVICE_TYPE = 'object-store'.freeze
META_DATA = { metadata: {}, content_type: 'application/json' }.freeze
COUNT = 100
def initialize(options)
# Enable frozen string literal:
# in one file with magick comment: frozen_string_literal: true
# enable globally: RUBYOPT="--enable-frozen-string-literal"
a = "a"
# copies everything about an object in Ruby except for its frozen state
b = a.dup
# copy everything about and object in Ruby
c = a.clone
/usr/local/bundle/gems/ffi-1.11.1/lib/ffi/library.rb:112: [BUG] Illegal instruction at 0x00007f54c94dea6b
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux-musl]
-- Control frame information -----------------------------------------------
c:0053 p:---- s:0272 e:000271 CFUNC :open
c:0052 p:0022 s:0266 e:000265 BLOCK /usr/local/bundle/gems/ffi-1.11.1/lib/ffi/library.rb:112 [FINISH]
c:0051 p:---- s:0257 e:000256 CFUNC :each
c:0050 p:0113 s:0253 e:000252 BLOCK /usr/local/bundle/gems/ffi-1.11.1/lib/ffi/library.rb:109 [FINISH]
c:0049 p:---- s:0246 e:000245 CFUNC :map
c:0048 p:0069 s:0242 e:000241 METHOD /usr/local/bundle/gems/ffi-1.11.1/lib/ffi/library.rb:99