Last active
May 10, 2016 19:52
-
-
Save mooreniemi/499ee3b5a6e1d566147a22f1fe2099a6 to your computer and use it in GitHub Desktop.
ruby is evil
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dog | |
end | |
class Cat | |
def self.new | |
Dog.new | |
end | |
end | |
#[3] amooreniemi (main) » Cat.new | |
#=> #<Dog:0x007fa052063c78> | |
#[4] amooreniemi (main) » | |
require 'objspace' | |
include ObjectSpace | |
#[5] amooreniemi (main) » memsize_of_all(Dog) | |
#=> 0 | |
#[6] amooreniemi (main) » memsize_of_all(Cat) | |
#=> 0 | |
#[7] amooreniemi (main) » Cat.new | |
#=> #<Dog:0x007febab922a18> | |
#[8] amooreniemi (main) » memsize_of_all(Cat) | |
#=> 0 | |
#[9] amooreniemi (main) » memsize_of_all(Dog) | |
#=> 40 | |
#[10] amooreniemi (main) » Cat.new | |
#=> #<Dog:0x007febaba17bf8> | |
#[11] amooreniemi (main) » memsize_of_all(Cat) | |
#=> 0 | |
#[12] amooreniemi (main) » memsize_of_all(Dog) | |
#=> 80 | |
#[13] amooreniemi (main) » Cat.new | |
#=> #<Dog:0x007febabab54e8> | |
#[14] amooreniemi (main) » memsize_of_all(Cat) | |
#=> 0 | |
#[15] amooreniemi (main) » memsize_of_all(Dog) | |
#=> 120 | |
#[16] amooreniemi (main) » |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dog | |
end | |
class Cat | |
def initialize | |
puts "dont do this" | |
end | |
def self.new | |
super # this allocates a cat! | |
Dog.new | |
end | |
end | |
require 'objspace' | |
include ObjectSpace | |
#[18] amooreniemi (main) » memsize_of_all(Cat) | |
#=> 0 | |
#[19] amooreniemi (main) » Cat.new | |
#dont do this | |
#=> #<Dog:0x007febabcffb90> | |
#[20] amooreniemi (main) » memsize_of_all(Cat) | |
#=> 40 | |
#[21] amooreniemi (main) » memsize_of_all(Dog) | |
#=> 160 | |
#[22] amooreniemi (main) » Cat.new | |
#dont do this | |
#=> #<Dog:0x007febac923228> | |
#[23] amooreniemi (main) » memsize_of_all(Dog) | |
#=> 200 | |
#[24] amooreniemi (main) » memsize_of_all(Cat) | |
#=> 80 | |
#[25] amooreniemi (main) » |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment