Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rubinius - Tales from the trenches @ Railsclub....

Rubinius - Tales from the trenches @ Railsclub.ru 2012

Dirkjan Bussink

September 15, 2012
Tweet

More Decks by Dirkjan Bussink

Other Decks in Programming

Transcript

  1. class Foo class << self class << self def foo;

    end end end end class Bar < Foo; end p Bar.singleton_class.foo
  2. class SomeList < Array def push(value) value = Proxy.new(value) if

    value.is_a?(String) ... end end alias_method :<<, :push end Unmarshal uses Array#<<
  3. class PropertySet < Array alias_method :superclass_slice, :[]= private :superclass_slice def

    []=(name, property) self << property end def <<(property) found = named?(property.name) add_property(property) if found superclass_slice(index(property), property) else super end end end WUT? Ugh Oh, let’s change the meaning!
  4. class PropertySet def []=(name, property) add_property(property) end def <<(property) add_property(property)

    end def add_property(property) clear_cache @order << property unless @order.include?(@property) @properties[property.name] = property end end
  5. GCC is fucking stupid. Avoid inane gcc type punning warning

    Work around GCC's broken strict aliasing checks. gcc 4.2.1 on freebsd 9 wants a newline at the end Make the gcc gods happy Make the stupid compiler gods happy Appease GCC 4.3
  6. class MyClass def to_ary puts "we're here" [1] end end

    def my_method arg yield arg end my_method(MyClass.new) do |*arg| p arg end we're here [#<MyClass:0xX>] we're here [1] we're here [[1]] [#<MyClass:0xX>] A B C D Call to_ary and ignore
  7. can't define singleton method "method" for Float obj = 2.0

    def obj.method puts "method on float instance" end obj.method No singleton methods on Numeric
  8. class Numeric def singleton_method_added(name) end end obj = 2.0 def

    obj.method puts "method on float instance" end obj.method method on float instance Singleton method on a Numeric!
  9. 3 4 5 6 Becomes true on first condition, false

    on second 10.times do |i| if (i == 3) .. (i == 6) puts i end end
  10. VALUE rb_data_object_alloc(VALUE klass, void *datap, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree) {

    NEWOBJ(data, struct RData); if (klass) Check_Type(klass, T_CLASS); OBJSETUP(data, klass, T_DATA); data->data = datap; data->dfree = dfree; data->dmark = dmark; return (VALUE)data; } MRI internals
  11. a = 0 b = 0 c = 0 d

    = 0 Core 1 Core 2 a = 1 c = 1 b = 2 d = 2 Statements can be executed in different order
  12. addr = Address.new addr.street = "Somestreet" addr.number = 1 shared_addr

    = addr shared_addr => nil shared_addr => #<Address:0x1c @street="Somestreet" @number=1> shared_addr => #<Address:0x1c> shared_addr => #<Address:0x1c @street="Somestreet"> shared_addr => #<Address:0x1c @number=1> shared_addr = addr executed before other assignments