hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

Friday

2007.01.19

I've Read Your Horoscope and You're No Hacker #

by why in inspect

What’s up with this job posting which demands a Gemini, Leo, Libra, Sagittarius or Aquarius?

The most ambitious Ruby on Rails project calls for a Rail’s guru to lead team as Co-founder

This is a wonderful entrepreneurial position for the humanitarian keen on facilitating emotional fulfilment for humanity.

*Birthday must fall between;

January 20 and February 18
May 21 and June 20
July 23 and August 22
Sept. 23 and Oct. 22
November 23 and December 21

Is this a phenomenon common to Germany? I’m sorry, the stars just aren’t aligned for you to code for us today. (Seen on onslaught.)

Wrapping a C Function as a Block #

by why in bits

I had previously been using rb_iterate and a call to Proc.new to build a block in C. But that takes two function calls while the undocumented rb_proc_new is just one.

 require 'rubygems'
 require 'inline'

 module Kernel
   inline do |ext|
     ext.prefix %{
       static VALUE sum(VALUE args)
       {
         return rb_funcall(rb_ary_entry(args, 0), rb_intern("+"), 1, 
           rb_ary_entry(args, 1));
         return Qnil;
       }
     }
     ext.c %{
       VALUE sum_block()
       {
         return rb_proc_new(sum, 0);
       }
     }
   end
 end

 p sum_block[13, 2]
 p (0..20).inject(0, &sum_block)

Most of the time rb_iterate is what you need. But, you know, in case you actually want a Proc object.