c++Öе÷ÓÃruby´úÂë
#include < ruby.h > //
static int id_sum;
int Values[] = {5, 10 ,15,-1,20,0};
static VALUE wrap_sum(VALUE args)
{
VALUE * values = (VALUE *) args;
VALUE summer = values[0];
VALUE max = values[1];
return rb_funcall(summer,id_sum,1,max);
}
static VALUE protected_sum(VALUE summer, VALUE max)
{
int error; VALUE args[2];
VALUE result;
args[0] = summer;
args[1] = max;
result = rb_protect(wrap_sum,(VALUE)args, &error);
return error ? Qnil:result;
}
int main()
{
int value;
int *next = Values;
ruby_init();
ruby_init_loadpath();
ruby_script("embedded");
rb_require("sum.rb");
VALUE summer = rb_class_new_instance(0,0,rb_const_get(rb_cObject,rb_intern("Summer")));
id_sum = rb_intern("sum");
while (value = *next++)
{
VALUE result = protected_sum(summer,INT2NUM(value));
if (NIL_P(result))
{
printf("Sum to %d doesn't compute!\n",value);
}
else
printf("Sum to %d is %d\n",value,NUM2INT(result));
}
ruby_finalize();
}
Ïà¹ØÎĵµ£º
CÊÇÃæÏò¹ý³ÌµÄ³ÌÐòÉè¼Æ£¬³ÌÐò=Êý¾Ý½á¹¹+Ëã·¨ [×îÔʼ£¬µ«±à¸ö³Ìȷʵ²»Ò×]
C++ÊÇÃæÏò¶ÔÏóµÄ³ÌÐòÉè¼Æ£¬³ÌÐò=¶à¸öÀà+ÏûÏ¢(Àà=Êý¾Ý½á+Ëã·¨)[±È½ÏÈÝÒ×ÉÏÊÖ]
C# ÊÇ´¿ÃæÏò¶ÔÏóµÄÓïÑÔ[¸ü¼Ó±È½ÏÈÝÒ×ÉÏÊÖ]
VC/VC++/VC# Ö»ÊÇÓÃÀ´¿ª·¢C/C++/C#Ó¦ÓóÌÐòµÄÈí¼þÖеÄÒ»ÖÖ¡£
......
Ruby 101£º·½·¨¶ÔÏó
Written by Allen Lee
´Ó·½·¨µ÷ÓÃ˵Æð
ÔÚÉÏһƪÎÄÕÂÀÎÒÃÇ¿´µ½µ÷ÓöÔÏóµÄ·½·¨ÊµÖÊÉÏÊÇÏò¶ÔÏó·¢ËÍÏûÏ¢£¬ÏÂÃ棬ÎÒÃÇÔÙÀ´¿´Ò»¸öÓÐȤµÄÓ¦Óá£ÔÚRubyÀ×Öµä¿ÉÒÔͨ¹ý {key => value} À´´´½¨£¬Èç¹ûÄãʹÓõİ汾ÊÇ1.9»òÒÔÉÏ£¬µ±keyµÄÀàÐÍÊÇSymbolʱ£¬´´½¨×ÖµäµÄÓ ......
ÔÚ×î½üµÄÒ»¸ö¹ØÓÚLKMLµÄÌÖÂÛÖУ¬Linus¸ø³öÁËΪʲô²»ÓÃC++À´Ð´LinuxÄں˵ÄÀíÓÉ£º
"In fact, in Linux we did try C++ once already, back in 1992. It sucks. Trust me - writing kernel code in C++ is a BLOODY STUPID IDEA.
“ÊÂʵÉÏ£¬ÎÒÃÇÔø¾³¢ÊÔ¹ýÓÃC++À´Ð´£¬ÊÇÔÚ1992ÄêµÄʱºò¡£ºÜÔã¸â¡£ÏàÐÅÎÒ--ÓÃC++À´Ð´ÄÚºË ......
±¾ÎĽéÉÜÁËRuby on RailsµÄÏêϸ°²×°²½Öè¡£ÎÄÖÐʹÓõÄRuby on Rails°æ±¾ÊÇ1.8.6-26¡£°²×°RubyÖ®ºó°²×°Rails£¬È»ºó¾Í¿ÉÒÔ´´½¨WebÓ¦Ó㬲¢ÔÚ±¾µØ²âÊÔÁË¡£
1¡¢°²×°ruby
²»ÓÃ˵ ÊÇÏÂÔØ°²×°°ü£ºhttp://rubyforge.org/frs/?group_id=167£¬×¢Òâ°æ±¾---º¦È˲»Ç³£¬ºóÃæ»á˵µ½£¬ÎÒϵÄÊÇ1.8.6-26
×°Íêºó£¬¿ÉÒÔÓÃruby -v ²âÊÔÊÇ·ñ° ......