显示标签为“ruby”的博文。显示所有博文
显示标签为“ruby”的博文。显示所有博文

2010年1月28日星期四

Tiny Extension to Ruby YAML


I am using Ruby's YAML library to dump objects to yaml document. The built in library dumps all fields, but in my program I only need to serialize part of them. So I need a way to set some fields to be transient.

I searched the web, and found Xavier's yaml_helper. It can solve my problem, but not exactly what I want. It uses class attribute "persistent" to indicating the fields to be serialized. In my suitation, there are many fields in the object, and only two or three are transient. So I prefer the "transient" class attribute.

After reading the source code of yaml_helper and Ruby's YAML library, I decided to write my own. Now, you can check it from here. It is no more than 100 lines code with most copied from yaml_helper, and realy a tiny tiny extension.

2007年11月14日星期三

使用rubygems安装rails

以前一直是使用sudo apt-get install rails来安装rails的,最近下载了redmine的源代码,想在自己机子上配置使用,但是在使用rake db:migrate创建数据库的时候报出require 'action_web_service'的错误,查了一下怀疑是安装rails的时候没有安装actionwebservice包的缘故,于是决定使用rubygems重新一下rails。使用sudo apt-get install rubygems虽然提示需要下载相应的安装包,但是下载时只有404错误。查了一下,听说ubuntu是不提供rubygems的apt-get安装的,原因好像是为了防止冲突。只能自己下载rubygems的包安装。把rubygems和rails都安装完后,再次配置redmine,一次就成功了。以此确定是因为用apt-get安装rails的问题,所以还是建议使用rubygems来安装rails,毕竟这是官方推荐的安装方式。现在把安装步骤写下来。
使用apt-get安装ruby的方法跟平常一样,在此不再赘述。首先从http://rubyforge.org/projects/rubygems/下载rubygems的安装包,当前最新版本是0.9.4。
$ tar xzvf rubygems-0.9.4.tgz
$ cd rubygems-0.9.4
$ sudo ruby setup.rb
$ sudo gem update --system
使用如上命令安装并更新rubygems。然后使用如下命令来安装rails及其依赖:
$ sudo gem install rails -y
会依次显示安装了actioncontroller,activerecord等包,正常退出则说明安装成功了,可以运行一下rails命令来测试一下。

2007年10月23日星期二