Skip to content

Instantly share code, notes, and snippets.

Avatar

Shugo Maeda shugo

View GitHub Profile
View gist:a23118ff9344ea0b968cffacb09186ab
module M1
refine String do
def foo
"M1#foo"
end
end
end
module M2
refine String do
View gist:14e65da37582593064b0f33d63b71cce
module M
refine String do
def foo
puts "foo"
end
end
end
def bar(&block)
block.using(M)
@shugo
shugo / benchmark.md
Last active Nov 9, 2019
Benchmark results of Immutable::Map
View benchmark.md

Original

Rehearsal ---------------------------------------------------------
Hash aset               0.028307   0.003103   0.031410 (  0.031495)
Hash aref               0.010025   0.000005   0.010030 (  0.010047)
Hash delete             0.012342   0.000065   0.012407 (  0.012558)
AVLTree aset            0.528481   0.002488   0.530969 (  0.531534)
AVLTree aref            0.159875   0.000126   0.160001 (  0.160148)
AVLTree delete          0.575293   0.002389   0.577682 (  0.578515)
View silver_j.md

問題1. 選択肢の中からRubyの予約語ではないものを2つ選択してください。

  • A.super
  • B.begin
  • C.try
  • D.goto

問題2. 以下のコードを実行した出力として正しいものを1つ選択してください。

def foo (a, *b)
 p a
@shugo
shugo / master.rb
Created Mar 16, 2019
Red/Green LED example
View master.rb
# mrblib/loops/master.rb
thermistor = Thermistor.new
led = Led.new(19)
led2 = Led.new(21)
while true
puts "temperature: #{thermistor.temperature}"
if thermistor.temperature > 30
led.turn_on
@shugo
shugo / gsub_wraper.rb
Created Nov 8, 2018
A wrapper method of gsub
View gsub_wraper.rb
require "fiddle"
LIBRUBY = Fiddle::Handle.new(nil)
RB_BACKREF_SET = Fiddle::Function.new(LIBRUBY["rb_backref_set"],
[Fiddle::TYPE_VOIDP],
Fiddle::TYPE_VOID)
def gsub_wrapper(str, re, &block)
str.gsub(re) { |s|
Thread.current[:backref] = Regexp.last_match
View t.rb
regular_file = "./regular"
symlinkfile = "./symlink"
File.delete(regular_file) rescue nil
File.delete(symlinkfile) rescue nil
File.open(regular_file, "w") {}
File.symlink(regular_file, symlinkfile)
p File.lstat(symlinkfile).atime
t = Time.local(2000)
stat = File.lstat(symlinkfile)
View gist:ab10be736a87be44ac25f7af199c41d5
Content-Disposition: attachment; filename=%81w%92%E8%97%9D%8F%D8%96%BE%8E%E8%8FK%82%A2%81x%81i%8E%86%8F%91%90%D0%81{%93d%8Eq%8F%91%90%D0%81j.pdf; filename*=UTF-8''%81w%92%E8%97%9D%8F%D8%96%BE%8E%E8%8FK%82%A2%81x%81i%8E%86%8F%91%90%D0%81{%93d%8Eq%8F%91%90%D0%81j.pdf; filename="%81w%92%E8%97%9D%8F%D8%96%BE%8E%E8%8FK%82%A2%81x%81i%8E%86%8F%91%90%D0%81{%93d%8Eq%8F%91%90%D0%81j.pdf"
View gist:93ba98025c84bcbc3fb1584bf7bce203
Content-Disposition:attachment; filename=%81w%92%E8%97%9D%8F%D8%96%BE%8E%E8%8FK%82%A2%81x%81i%8E%86%8F%91%90%D0%81{%93d%8Eq%8F%91%90%D0%81j.pdf; filename="%81w%92%E8%97%9D%8F%D8%96%BE%8E%E8%8FK%82%A2%81x%81i%8E%86%8F%91%90%D0%81{%93d%8Eq%8F%91%90%D0%81j.pdf"
View t.rb
module M
refine String do
def gsub(*args)
super(*args) {
yield $~
}
end
end
end
You can’t perform that action at this time.