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
$ bin/ruby -v | |
ruby 2.4.0dev (2016-09-12 master 56141) [x86_64-linux] | |
$ bin/ri | |
ri 5.0.0.beta2 | |
$ bin/ri String | |
= String < Object | |
------------------------------------------------------------------------------ |
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
module DidYouMean | |
class MethodNameChecker | |
prepend Module.new { | |
PY2RB = { | |
String => { | |
lower: %i(downcase) | |
}, | |
Object => { | |
len: %i(obj.length) | |
} |
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
user system total real | |
Yhpg.new(actual).output == expect 0.210000 0.010000 0.220000 ( 0.228040) | |
assert { Yhpg.itself.new(actual).output == expect } 1.650000 0.000000 1.650000 ( 1.650489) | |
assert { Yhpg.new(actual).output == expect } 115.110000 0.000000 115.110000 (115.058014) |
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) | |
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
# 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/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
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
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' | |
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 |