Archive for the ‘Ruby’ Category

GC and ObjectSpace

Friday, August 24th, 2007

I saw this at the Rails Edge conference and thought it was cool; aside from its really expensive to implement in JRuby.

1
2
3
4
5
6
7
8
9
10
>> GC.disable
=> false
>> instances = 0
=> 0
>>  ObjectSpace.each_object(Artist) { |a| instances += 1 }
=> 0
>> Artist.find(:all, :limit => 5)
=> [#<Artist:0x327d348 @attributes={....
>>  ObjectSpace.each_object(Artist) { |a| instances += 1 }
=> 5

Network Facade API

Friday, June 8th, 2007

I was looking at the NetworkFacade api, (check it out at network-facade.rubyforge.org) and noticed:

1
2
3
  # Or declate the Foo class and set an uri
  class Foo < NetworkFacade::Client 'nf://localhost:5042'
  end

where the uri is defined with the Foo declaration. Foo descends from the class returned by the Client class method.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module NetworkFacade

    def self.Client(uri = nil)
        TCP::Client.uri = uri
        TCP::Client
    end

    class Client < TCP::Client
    end


    class Server < TCP::Server
    end

end

That is cool.