Skip to content

Instantly share code, notes, and snippets.

/**
EasyVR Tester
Dump contents of attached EasyVR module
and exercise it with playback and recognition.
Serial monitor can be used to send a few basic commands:
'c' - cycles through available command groups
'b' - cycles through built-in word sets
's123.' - play back sound 123 if available (or beep)
@pH14
pH14 / rubinius backreferences class
Created November 14, 2013 01:10
In Rubinius 2.1.1 the $`, $', $+, $&, $1-$9 backreferences don't maintain the class of the original matched string. The $~ MatchData will return the correct class.
class LabeledString < String
end
s1 = LabeledString.new("Secret Name")
/n(a)(m)e/i =~ s1
p [$1, $1.class, LabeledString]
p [$2, $2.class, LabeledString]
p [$`, $`.class, LabeledString]
@pH14
pH14 / rubinius string#match example
Created November 2, 2013 05:31
Example of differing behavior in MRI2.0.0 vs Rubinius2.1.1
class RegexpSub < Regexp
def match *args
"regexp_match"
end
end
reg = RegexpSub.new("he")
p "hello".match(reg) == "regexp_match"
@pH14
pH14 / match_spec.rb output
Last active December 27, 2015 05:39
Rubinius failing String#match spec
pwh-argon:rubinius pwh$ rvm use ruby
Using /Users/pwh/.rvm/gems/ruby-2.0.0-p247
pwh-argon:rubinius pwh$ bin/mspec -tr core/string/match_spec.rb
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.3.0]
......................
Finished in 0.003534 seconds
1 file, 22 examples, 37 expectations, 0 failures, 0 errors
@pH14
pH14 / ll_test.rb
Last active December 23, 2015 22:39 — forked from pwnall/ll_test.rb
class LabeledString < String
def +(other)
LabeledString.new original_plus(other)
end
end
class String
alias_method :original_plus, :+
def +(other)