Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Native MRI callback

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 bench
Octocat-spinner-32 ext
Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 README
Octocat-spinner-32 Rakefile
Octocat-spinner-32 cb.gemspec
README
Simple native Callback object for Ruby MRI
  (c) 2009 Lourens Naudé (methodmissing), James Tucker (raggi) and coderrr
 
  http://github.com/methodmissing/cb

This library works with Ruby 1.8 and 1.9 and is a more efficient
implementation of the following Ruby code :

  class RubyCallback
    def initialize(object = nil, method = :call, &b)
      @object, @method = object, method
      @object ||= b
    end
  
    def call(*args)
      @object.__send__(@method, *args)
    end
  end

  module Kernel
    private
    def RubyCallback(object = nil, method = :call, &b)
      RubyCallback.new(object, method, &b)
    end
  end

Concept, ideas and API design James's - any pointers for better GC integration much appreciated.

Examples :

  'hai'.callback(:gsub).call('h', 'b') #=> 'bai'
  Callback( 'bai', :to_s ).call #=> 'hai'
  Callback{ 'hai' }.call #=> 'hai'
  Callback( 'bai', :gsub ).call( 'b', 'h' ) #=> 'hai'

To run the test suite:

  rake

To run the benchmarks:

  rake bench
Something went wrong with that request. Please try again.