Skip to content

Instantly share code, notes, and snippets.

View dwaite's full-sized avatar
💭
Wondering what status is for

David Waite dwaite

💭
Wondering what status is for
View GitHub Profile
#include <stdio.h>
/* prints 78.882004 */
int main(int argc, char** argv) {
float f = 78.882;
printf("%f\n", f);
return 0;
}
$ RBXOPT=-Xprofile\ -Xprofiler.graph\ -Xprofiler.full_report rbx -S rspec spec -f p &>foo
bash-3.2$ vim foo
bash-3.2$ grep Array#map foo
0.00 0.22 1 Array#map [74]
[74] 0.3 0.00 0.22 1 Array#map [74]
0.00 0.22 1 Array#map [74]
0.00 0.22 4 Array#map [76]
[76] 0.3 0.00 0.22 4 Array#map [76]
0.00 0.22 4 Array#map [76]
0.00 0.22 1 Array#map [80]
ruby-1.9.2-p180 :008 > z = Fiber.new{Thread.current}.resume
=> #<Thread:0x00000100887678 run>
ruby-1.9.2-p180 :009 > Thread.current
=> #<Thread:0x00000100887678 run>
ruby-1.9.2-p180 :010 > z = Fiber.new{Thread.current.object_id}.resume
=> 2151955260
ruby-1.9.2-p180 :011 > Thread.current.object_id
=> 2151955260
@dwaite
dwaite / gist:869451
Created March 14, 2011 16:59
regexp-test.rb
def foo
puts "before: '#{$~}'"
/foo/ =~ 'foo'
puts "after: '#{$~}'"
clear_last_match
puts "after call: '#{$~}' (should still be set)"
end
def clear_last_match
$~ = nil
# Performs normal match and returns MatchData object from $~ or nil.
def match(str)
unless str
Regexp.last_match = nil
return nil
end
str = StringValue(str)
Regexp.last_match = search_region(str, 0, str.size, true)
# Performs normal match and returns MatchData object from $~ or nil.
def match(str)
unless str
Regexp.last_match = nil
return nil
end
str = StringValue(str)
Regexp.last_match = search_region(str, 0, str.size, true)
rbx-head-hydra :002 > foo = /foo/.match "foo"
=> #<MatchData "foo">
rbx-head-hydra :003 > bar = /bar/.match "bar"
=> #<MatchData "bar">
rbx-head-hydra :004 > $~
=> #<MatchData "bar">
rbx-head-hydra :005 > $~ = foo
=> #<MatchData "foo">
rbx-head-hydra :006 > $~
=> #<MatchData "bar">
diff --git a/spec/ruby/language/regexp/back-references_spec.rb b/spec/ruby/langu
index c09a165..fe0d9e0 100644
--- a/spec/ruby/language/regexp/back-references_spec.rb
+++ b/spec/ruby/language/regexp/back-references_spec.rb
@@ -7,6 +7,13 @@ describe "Regexps with back-references" do
$~.to_a.should == ["ll"]
end
+ it 'allows the $~ pseudo-global varable to be assigned' do
+ "hello" =~ /l+/
$ bundle exec rspec spec -fd
Callisto::Lexer
#tokenize
tokenizes a blank message to an empty array
tokenizes 'key' into a single identifier
tokenizes 'foo bar' into two identifiers
tokenizes hex numbers
tokenizes integers
tokenizes numbers starting with a decimal point
rvm install --trace --branch hydra rbx-hydra
--trace --branch hydra rbx-hydra
rvm 1.2.8 by Wayne E. Seguin (wayneeseguin@gmail.com) [http://rvm.beginrescueend.com/]
+ [[ -z '' ]]
+ export 'PS4=+[${BASH_SOURCE}] : ${LINENO} : ${FUNCNAME[0]:+${FUNCNAME[0]}() $ }'
+ PS4='+[${BASH_SOURCE}] : ${LINENO} : ${FUNCNAME[0]:+${FUNCNAME[0]}() $ }'
+[/Users/david/.rvm/scripts/cli] : 705 : __rvm_parse_args() $ [[ -z install ]]
+[/Users/david/.rvm/scripts/cli] : 707 : __rvm_parse_args() $ [[ 0 -eq 1 ]]