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
require 'pattern-match' | |
def replace_repeated(val, &block) | |
ret = match(val, &block) | |
if ret == val | |
ret | |
else | |
replace_repeated(ret, &block) | |
end | |
rescue PatternMatch::NoMatchingPatternError |
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
$ make TESTS='--gc-stress objspace/test_objspace.rb pathname/test_pathname.rb' test-all | |
TestPathname#test_each_entry/home/kazuki/work/ruby/lib/pp.rb:165: [BUG] Segmentation fault | |
ruby 2.1.0dev (2013-04-25 trunk 40462) [x86_64-linux] | |
-- Control frame information ----------------------------------------------- | |
c:0061 p:0008 s:0261 e:000259 METHOD /home/kazuki/work/ruby/lib/pp.rb:165 | |
c:0060 p:0011 s:0255 e:000254 BLOCK /home/kazuki/work/ruby/lib/pp.rb:356 | |
c:0059 p:0029 s:0252 e:000251 BLOCK /home/kazuki/work/ruby/lib/pp.rb:247 [FINISH] | |
c:0058 p:---- s:0249 e:000248 CFUNC :each |
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
diff --git a/array.c b/array.c | |
index 9a93d7f..b673c63 100644 | |
--- a/array.c | |
+++ b/array.c | |
@@ -4429,7 +4429,7 @@ static VALUE sym_random; | |
static VALUE | |
rb_ary_shuffle_bang(int argc, VALUE *argv, VALUE ary) | |
{ | |
- VALUE opts, randgen = rb_cRandom; | |
+ VALUE rnd, randgen = rb_cRandom; |
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
require 'pattern-match' | |
class Module | |
def check(pattern, mid) | |
prepend Module.new { | |
define_method(mid) do |*args| | |
ret = super(*args) | |
match(ret) do | |
with(Kernel.eval(pattern, Kernel.binding)) { ret } | |
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
require 'pattern-match' | |
class Object | |
def assert_pattern(pattern) | |
match(self) do | |
with(Kernel.eval(pattern, Kernel.binding)) { self } | |
end | |
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
require 'pattern-match' | |
require 'set' | |
module PatternMatch | |
class PatternSetDeconstructor < PatternDeconstructor | |
def initialize(klass, *subpatterns) | |
super(*subpatterns) | |
@klass = klass | |
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
diff --git a/parse.y b/parse.y | |
index 3f756ce..680242d 100644 | |
--- a/parse.y | |
+++ b/parse.y | |
@@ -10705,7 +10705,13 @@ rb_str_dynamic_intern(VALUE str) | |
ID id, type; | |
if (st_lookup(global_symbols.sym_id, str, &id)) { | |
- return ID2SYM(id); | |
+ VALUE sym = ID2SYM(id); |
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
# power_assert.rb | |
# | |
# Copyright (C) 2014 Kazuki Tsujimoto, All rights reserved. | |
# License: BSDL | |
# | |
# $ ruby power_assert.rb | |
# "0".class == "3".to_i.times.map {|i| i + 1 }.class | |
# | | | | | | |
# | | | | Array | |
# | | | [1, 2, 3] |
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
diff --git a/lib/power_assert.rb b/lib/power_assert.rb | |
index 1a19d07..51064f1 100644 | |
--- a/lib/power_assert.rb | |
+++ b/lib/power_assert.rb | |
@@ -5,7 +5,23 @@ | |
require 'power_assert/version' | |
require 'ripper' | |
-require 'pattern-match' | |
+require 'pattern-match/core' |
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
ruby -v -rstringio -rbenchmark -e 'N=1_000_000;Benchmark.bm(5){|x| x.report("String#<<"){s="";N.times{s<<"a"}}; x.report("Array#<<+join"){a=[];N.times{a<<"a"};a.join}; x.report("StringIO#<<"){i=StringIO.new;N.times{i<<"a"};i.to_s}};' | |
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux] | |
user system total real | |
String#<< 0.150000 0.000000 0.150000 ( 0.149649) | |
Array#<<+join 0.200000 0.030000 0.230000 ( 0.231170) | |
StringIO#<< 0.250000 0.010000 0.260000 ( 0.255604) | |