Skip to content

Instantly share code, notes, and snippets.

View wilson's full-sized avatar

Wilson Bilkovich wilson

View GitHub Profile
@wilson
wilson / gist:234170
Created November 13, 2009 21:17
merge two sorted arrays
#!/usr/bin/env ruby
require 'time'
require 'benchmark'
class Thing
attr_accessor :timestamp
def initialize(timestamp)
@timestamp = timestamp
end
### running this code: http://gist.github.com/234170
### jruby trunk from last week
> jruby sorting.rb
Rehearsal ---------------------------------------------
merge: 1.070000 0.000000 1.070000 ( 1.070000)
nocopy: 0.730000 0.000000 0.730000 ( 0.730000)
------------------------------------ total: 1.800000sec
user system total real
本拠> bin/rbx ../sorting.rb
Rehearsal ---------------------------------------------
merge: 2.448515 0.000000 2.448515 ( 2.448516)
nocopy: 0.896591 0.000000 0.896591 ( 0.896639)
------------------------------------ total: 3.345106sec
user system total real
merge: 0.855341 0.000000 0.855341 ( 0.855353)
nocopy: 0.569976 0.000000 0.569976 ( 0.569993)
x,y,z = "X ", "Y ", "Z "
[x,y,z].each_with_index do |str, i|
str << str[0,1]
p str
redo if i == 1
end
puts "ruby version: #{RUBY_VERSION}"
pass = 0
proc do |@x|
pass += 1
puts "proc pass number #{pass}"
@x = 3 if pass == 1
puts "proc x is: #{@x}"
redo if pass != 2
module IncludeMe;end
module BehindTheScenes;end
# Include IncludeMe in a module
module One
include IncludeMe
end
# Add an ancestor to IncludeMe
module IncludeMe
Process: vm [69929]
Path: /Users/wilson/code/rbx/vm/vm
Identifier: vm
Version: ??? (???)
Code Type: X86-64 (Native)
Parent Process: zsh [37874]
Date/Time: 2009-11-22 04:23:08.915 -0500
OS Version: Mac OS X 10.6.2 (10C540)
Report Version: 6
# shortcut method for opening a metaclass on the receiver
module Kernel;def m;class << self;self;end;end;end
Module.m # #<Class:Module>, metaclass of Module
Module.m.superclass # Class, because that is how Module is bootstrapped
Module.m.m # #<Class:#<Class:Module>>, metaclass of Module's metaclass
Module.m.superclass # #<Class:#<Class:Module>>
Module.m.m.superclass # #<Class:#<Class:Module>>
# Opening a metaclass on Module's metaclass changes its superclass to be the same as its metaclass's superclass!?
(gdb) rp already_meta->true_superclass(state)
#<Module(Class):0x101225df0>
name: :Module
superclass: #<Object(Class):0x101225d70>
constants: #<Rubinius::LookupTable:0x1014010a0>
method_table: #<Rubinius::MethodTable:0x101401170>: 18
:constant_table, :direct_superclass, :attr_writer, :protected, :alias_method, :module_function, :const_set, :encloser, :name, :append_features, :included, :attr_accessor, :const_missing, :include, :method_table, :superclass=, :attr_reader, :private
>
>
$2 = void
Breakpoint 1, rubinius::MetaClass::attach (state=0x101204b00, obj=0x101226220, sup=0x0) at vm/builtin/class.cpp:204
204
(gdb) rp already_meta
#<MetaClass:Class Object:0x101226220>
$1 = void
(gdb) rp already_meta->superclass()
#<Class(Class):0x101225c70>
name: :Class
superclass: #<Module(Class):0x101225df0>
constants: #<Rubinius::LookupTable:0x101400ed0>