Skip to content

Instantly share code, notes, and snippets.

require 'pp'
class Hash::Weak < Hash
def []( key )
# get the stored ID - a FixNum, not an object reference to our weak-referenced object
obj_id = super( key.to_sym )
# theoretically this should cause non-referenced objects to get cleaned up
VALUE rb_index = Qnil;
VALUE rb_key = Qnil;
VALUE rb_hash_descriptor_index_key = Qnil;
VALUE rb_hash_descriptor_index_keys_array = Qnil;
VALUE rb_args_array = Qnil;
RARG_Define(
/*----------------------------------------------*/
class << fiber_instance
extend Enumerable
attr_accessor :internal_enumerator
def each( & block )
raise RuntimeError, "no internal enumerator specified"
return internal_enumerator.next
end
end
cmake_minimum_required(VERSION 2.6)
project( rb_rpdb C )
# add local modules path for project
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/" )
# where to look for source files (headers and source)
include_directories( rpdb/include )
include( RecursivelyIncludeSource )
set( _RUBY_DEBUG_OUTPUT ON)
# make sure we have libdb
find_package( RPDB REQUIRED )
find_package( Ruby REQUIRED )
message( STATUS "Using RPDB Lib: ${RPDB_LIBRARY}" )
message( STATUS "Using Ruby Lib: ${RUBY_LIBRARY}" )
# function processes each sub-directory and then adds each source file in directory
# each function should cascade back upward in setting variables so that the bottom directory
# adds its source first, and then the level above it adds its source and passes both up, and so on...
function( recursively_include_src which_directory return_variable )
if( ${return_variable} STREQUAL "headers" )
set( file_extension ".h" )
else( ${return_variable} STREQUAL "headers" )
set( file_extension ".c" )
endif( ${return_variable} STREQUAL "headers" )
/**************************
* retrieve_data_for_key *
* retrieve_for_key *
* retrieve *
**************************/
// database.retrieve( primary_key )
// database.retrieve( :index, secondary_key )
// database.retrieve( :index => secondary_key_in_index )
// database.retrieve( :index => [ secondary_keys_in_index, ... ] )
class A
def method
puts 'do some stuff'
end
def method_with_same_name_as_in_module
end
@Asher-
Asher- / prepend.c
Created October 10, 2010 07:11 — forked from banister/prepend.c
/* (c) 2010 John Mair (banisterfiend), Asher (Asher), MIT license */
#include "compat.h"
#include "ruby.h"
VALUE
rb_prepend_methods(VALUE klass)
{
VALUE m = rb_module_new();
st_free_table(RCLASS_M_TBL(m));
#include <stdio.h>
void input() {
float input_temperature_f;
printf( "Input temperature in Fahrenheit.\n" );
scanf( "%f", &input_temperature_f );
}