Skip to content

Instantly share code, notes, and snippets.

Tomohiko Mimura mito5525

Block or report user

Report or block mito5525

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mito5525
mito5525 / ruby kernel-array-vs-array-wrap
Last active Jan 14, 2020
Ruby Kernel.Array vs Array#wrap
View ruby kernel-array-vs-array-wrap
$ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18]
$ cat benchmark.yml
prelude: |
require 'active_support/core_ext/array/wrap'
a = nil
benchmark:
Kernel#Array(nil): Array(a)
Array#wrap(nil): Array.wrap(a)
View keybase.md

Keybase proof

I hereby claim:

  • I am mito5525 on github.
  • I am t_mimura (https://keybase.io/t_mimura) on keybase.
  • I have a public key whose fingerprint is E6C2 AFF9 A69E 053A EBD7 E530 9F32 F8DE 1BE1 FD4D

To claim this, I am signing this object:

View instance_variables
~$ ruby -v
ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-darwin18]
~$ irb
irb(main):001:0> class A
irb(main):002:1> attr_accessor :id, :name
irb(main):003:1> end
=> nil
irb(main):004:0> a = A.new
=> #<A:0x00007fab848cdde0>
irb(main):005:0> a.instance_variables
@mito5525
mito5525 / struct_keyword_init.rb
Last active Jan 14, 2020
Ruby Struct new.tap vs keyword_init
View struct_keyword_init.rb
require 'benchmark_driver'
Benchmark.driver do |x|
x.prelude <<~RUBY
Hoge = Struct.new(:a)
Fuga = Struct.new(:a, keyword_init: true)
i = 1
RUBY
x.report 'new_and_tap', %{ Hoge.new.tap { |h| h.a = i } }
You can’t perform that action at this time.