Rubinius - Tales from the trenches @ Railsclub.ru 2012

Rubinius - Tales from the trenches @ Railsclub.ru 2012

B012094b37ab6946c44eaa41d7828478?s=128

Dirkjan Bussink

September 15, 2012
Tweet

Transcript

  1. 3.
  2. 4.
  3. 7.
  4. 8.
  5. 9.

    class Foo class << self class << self def foo;

    end end end end class Bar < Foo; end p Bar.singleton_class.foo
  6. 11.

    class SomeList < Array def push(value) value = Proxy.new(value) if

    value.is_a?(String) ... end end alias_method :<<, :push end Unmarshal uses Array#<<
  7. 13.
  8. 14.

    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!
  9. 15.

    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
  10. 16.
  11. 17.
  12. 19.
  13. 20.

    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
  14. 22.

    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
  15. 23.

    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
  16. 24.

    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!
  17. 25.

    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
  18. 28.

    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
  19. 30.
  20. 32.
  21. 33.
  22. 35.
  23. 38.

    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
  24. 39.

    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