11 11, 2004

YAML ºÍ Ruby

YAML£ºYAML Ain't Markup Language£¨http://yaml.org£©£¬Ò»ÖÖ¼òµ¥Ò×¶ÁµÄÓÃÀ´±íÊ¾ÌØ¶¨µÄÊý¾Ý½á¹¹µÄÓïÑÔ¡£¿ÉÒÔÓÃÔÚ¸÷Öֽű¾ÓïÑÔÖУ¬±ÈÈçperl£¬python£¬rubyµÈ¡£¿ÉÒÔʵÏÖjavaÖÐÀàËÆcastorµÄ XML MAPPINGµÈ¹¦ÄÜ£¬±ÈÈç¸ù¾ÝÅäÖÃÎļþÉú³É¶ÔÏóµÈ¡£

# file name zhu.rb

require 'yaml'

class Person

  attr_accessor :name, :sex, :age, :email

  def initialize
    @name="liubin"
    @sex="male"
    @age=25
    @email="liubin at huangpuzhuang.com"
  end
 
  def doSomthing
      puts " do somthing "   
  end
end


person=Person.new()
puts (person.to_yaml)

C:>ruby zhu.rb
--- !ruby/object:Person
age: 25
email: liubin at huangpuzhuang.com
name: liubin
sex: male

C:>

×îлظ´