{"id":1443,"date":"2006-07-27T19:43:45","date_gmt":"2006-07-27T11:43:45","guid":{"rendered":"http:\/\/ihower.idv.tw\/blog\/archives\/1443"},"modified":"2008-09-29T01:15:19","modified_gmt":"2008-09-28T17:15:19","slug":"yaml-%e7%b0%a1%e4%bb%8b","status":"publish","type":"post","link":"https:\/\/ihower.tw\/blog\/1443-yaml-%e7%b0%a1%e4%bb%8b","title":{"rendered":"YAML \u7c21\u4ecb"},"content":{"rendered":"<p>Rails \u7684\u8cc7\u6599\u5eab\u8a2d\u5b9a\u6a94 database.yml \u662f\u7528\u4e00\u7a2e\u53eb YAML\u00a0\u7684\u683c\u5f0f\u6240\u64b0\u5beb\uff0c\u6a94\u6848\u6253\u958b\u4f86\uff0c\u770b\u8d77\u4f86\u5c31\u50cf\u4e00\u822c\u7684 plain \u8a2d\u5b9a\u6a94\uff0c\u975e\u5e38\u5bb9\u6613\u4fee\u6539\u3002<\/p>\n<p>YAML \u7684\u8a2d\u8a08\u9996\u8981\u76ee\u6a19\u5c31\u662f\u8981\u8b93\u4f7f\u7528\u8005\u5bb9\u6613\u770b\u61c2\uff0c\u53ef\u4ee5\u548c script \u8a9e\u8a00\u642d\u914d\u826f\u597d\u3002\u7528\u9014\u6709 \u8cc7\u6599\u5e8f\u5217\u5316 data serialization\u3001\u8a2d\u5b9a\u6a94 configuration settings\u3001log files\u3001Internet messaging\u3001filtering \u7b49\u3002\u7db2\u7ad9\u4e0a\u5df2\u77e5\u6709\u652f\u63f4\u7684 script \u8a9e\u8a00\u6709 Python,Ruby,Java,PHP,Perl,Javascript \u7b49\u3002<\/p>\n<p>\u53c3\u8003\u8cc7\u6599:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.yaml.org\/\">YAML \u7db2\u7ad9<\/a><\/li>\n<li><a href=\"http:\/\/anw.stikipad.com\/ocean\/show\/RubyYAML\">Ruby YAML \u4f7f\u7528\u7c21\u4ecb<\/a>\u00a0<\/li>\n<li><a href=\"http:\/\/www.dev.idv.tw:8080\/folder.2005-02-27.6191275545\/folder.2005-02-14.5124708507\/folder.2005-02-14.9700538108\/document.2005-02-26.4493274749\">YAML \u7c21\u4ecb<\/a><\/li>\n<\/ul>\n<p><!--more--><\/p>\n<p>\u4e00\u500b\u7bc4\u4f8b\uff0c\u5176\u4e2d<\/p>\n<blockquote><p>invoice: 34843<br \/>\ndate\u00a0\u00a0 : 2001-01-23<br \/>\nbill-to: &amp;id001<br \/>\n\u00a0\u00a0\u00a0 given\u00a0 : Chris<br \/>\n\u00a0\u00a0\u00a0 family : Dumars<br \/>\n\u00a0\u00a0\u00a0 address:<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 lines: |<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 458 Walkman Dr.<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Suite #292<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 city\u00a0\u00a0\u00a0 : Royal Oak<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 state\u00a0\u00a0 : MI<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 postal\u00a0 : 48046<br \/>\nship-to: *id001<br \/>\nproduct:<br \/>\n\u00a0\u00a0\u00a0 &#8211; sku\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : BL394D<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 quantity\u00a0\u00a0\u00a0 : 4<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 description : Basketball<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 price\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : 450.00<br \/>\n\u00a0\u00a0\u00a0 &#8211; sku\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : BL4438H<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 quantity\u00a0\u00a0\u00a0 : 1<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 description : Super Hoop<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 price\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : 2392.00<br \/>\ntax\u00a0 : 251.42<br \/>\ntotal: 4443.52<br \/>\ncomments: &gt;<br \/>\n\u00a0\u00a0\u00a0 Late afternoon is best.<br \/>\n\u00a0\u00a0\u00a0 Backup contact is Nancy<br \/>\n\u00a0\u00a0\u00a0 Billsmer @ 338-4338.<\/p><\/blockquote>\n<p>\u7528 Ruby \u8b80\u9032\u8cc7\u6599<\/p>\n<blockquote><p>require &#8216;yaml&#8217;<\/p>\n<p>ps2 = YAML.load_file(&#8216;y.yaml&#8217;)<br \/>\nps2.each do |it|<br \/>\n\u00a0 puts it.inspect<br \/>\nend<\/p><\/blockquote>\n<p>\u8b80\u51fa\u4f86 inspect \u7684\u7d50\u679c\u662f<\/p>\n<blockquote><p>[&#8220;tax&#8221;, 251.42]<\/p>\n<p>[&#8220;bill-to&#8221;,\u00a0{<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0 &#8220;given&#8221;=&gt;&#8221;Chris&#8221;,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8220;family&#8221;=&gt;&#8221;Dumars&#8221;,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0&#8220;address&#8221;=&gt; {<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8220;postal&#8221;=&gt;48046,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8220;city&#8221;=&gt;&#8221;Royal Oak&#8221;,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;lines&#8221;=&gt;&#8221;458 Walkman Dr.\\nSuite #292\\n&#8221;,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8220;state&#8221;=&gt;&#8221;MI&#8221;}<br \/>\n}]<\/p>\n<p>[&#8220;comments&#8221;, &#8220;Late afternoon is best. Backup contact is Nancy Billsmer @ 338-433<br \/>\n8.\\n&#8221;]<\/p>\n<p>[&#8220;invoice&#8221;, 34843]<\/p>\n<p>[&#8220;date&#8221;, #]<\/p>\n<p>[&#8220;total&#8221;, 4443.52]<\/p>\n<p>[&#8220;product&#8221;,<br \/>\n\u00a0\u00a0\u00a0\u00a0 \u00a0[<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {&#8220;price&#8221;=&gt;450.0, &#8220;quantity&#8221;=&gt;4, &#8220;description&#8221;=&gt;&#8221;Basketball&#8221;, &#8220;sku&#8221;=<br \/>\n&gt;&#8221;BL394D&#8221;},<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {&#8220;price&#8221;=&gt;2392.0, &#8220;quantity&#8221;=&gt;1, &#8220;description&#8221;=&gt;&#8221;Super Hoop&#8221;, &#8220;sku&#8221;=<br \/>\n&gt;&#8221;BL4438H&#8221;}<br \/>\n\u00a0\u00a0\u00a0\u00a0 ]<br \/>\n]<\/p>\n<p>[&#8220;ship-to&#8221;, {&#8220;given&#8221;=&gt;&#8221;Chris&#8221;, &#8220;family&#8221;=&gt;&#8221;Dumars&#8221;, &#8220;address&#8221;=&gt;{&#8220;postal&#8221;=&gt;48046,<br \/>\n&#8220;city&#8221;=&gt;&#8221;Royal Oak&#8221;, &#8220;lines&#8221;=&gt;&#8221;458 Walkman Dr.\\nSuite #292\\n&#8221;, &#8220;state&#8221;=&gt;&#8221;MI&#8221;}}]<\/p><\/blockquote>\n<p>Rails Receipts \u4e00\u66f8\u63d0\u5230\u4f60\u53ef\u4ee5\u9019\u6a23\u904b\u7528\u5728 database.yml :<\/p>\n<blockquote><p>defaults: &amp;defaults<br \/>\n\u00a0 adapter: mysql<br \/>\n\u00a0 username: root<br \/>\n\u00a0 password:\u00a0abcdef<br \/>\n\u00a0 socket: \/tmp\/mysql.sock<\/p>\n<p>development:<br \/>\n\u00a0 database: xxx_development<br \/>\n\u00a0 &lt; &lt;: *defaults<\/p>\n<p>test:<br \/>\n\u00a0 database: xxx_test<br \/>\n\u00a0 &lt;&lt;: *defaults<\/p>\n<p>production:<br \/>\n\u00a0 database: xxx_productuin<br \/>\n\u00a0 &lt;&lt;: *defaults<\/p><\/blockquote>\n<p>\u9019\u6a23\u7684\u8a71\uff0c\u90fd\u6703\u4f7f\u7528\u4e00\u6a23\u7684\u5e33\u865f\u5bc6\u78bc\u8a2d\u5b9a\u5566\u3002<\/p>\n<blockquote><\/blockquote>\n<blockquote><\/blockquote>\n<blockquote><\/blockquote>\n<blockquote><\/blockquote>\n<blockquote><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Rails \u7684\u8cc7\u6599\u5eab\u8a2d\u5b9a\u6a94 database.yml \u662f\u7528\u4e00\u7a2e\u53eb YAML\u00a0\u7684\u683c\u5f0f\u6240\u64b0\u5beb\uff0c\u6a94\u6848\u6253\u958b\u4f86\uff0c\u770b\u8d77\u4f86\u5c31 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/ihower.tw\/blog\/1443-yaml-%e7%b0%a1%e4%bb%8b\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008YAML \u7c21\u4ecb\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5,53,31],"tags":[],"class_list":["post-1443","post","type-post","status-publish","format-standard","hentry","category-programming","category-rails","category-ruby","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1q6tG-nh","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/1443","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/comments?post=1443"}],"version-history":[{"count":0,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/1443\/revisions"}],"wp:attachment":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/media?parent=1443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/categories?post=1443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/tags?post=1443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}