diff options
author | why <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-07-30 20:38:41 +0000 |
---|---|---|
committer | why <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-07-30 20:38:41 +0000 |
commit | a2523332ce58ab4af4f531306ebbdf10bacaa892 (patch) | |
tree | fe2f47fc4a44f80f7c57f2d52455cfdcc2be9ce8 /lib/yaml.rb | |
parent | eb851961c794995cc75024ab7366f866c31fdf7c (diff) | |
download | ruby-a2523332ce58ab4af4f531306ebbdf10bacaa892.tar.gz |
* lib/yaml.rb (YAML::load_file, YAML::parse_file): added.
* lib/yaml/rubytypes.rb: exceptions were using an older
YAML.object_maker. [ruby-core:03080]
* ext/syck/token.c (sycklex_yaml_utf8): using newline_len to
handline CR-LFs. "\000" was showing up on folded blocks which
stopped at EOF.
* ext/syck/token.c: re2c compiled with bit vectors now.
* ext/syck/implicit.c: ditto.
* ext/syck/bytecode.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/yaml.rb')
-rw-r--r-- | lib/yaml.rb | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/lib/yaml.rb b/lib/yaml.rb index 023c4ab84b..38463404bd 100644 --- a/lib/yaml.rb +++ b/lib/yaml.rb @@ -105,7 +105,7 @@ module YAML end # - # Load the first document from the current _io_ stream. + # Load a document from the current _io_ stream. # # File.open( 'animals.yaml' ) { |yf| YAML::load( yf ) } # #=> ['badger', 'elephant', 'tiger'] @@ -119,6 +119,18 @@ module YAML yp = @@parser.new.load( io ) end + # + # Load a document from the file located at _filepath_. + # + # YAML.load_file( 'animals.yaml' ) + # #=> ['badger', 'elephant', 'tiger'] + # + def YAML.load_file( filepath ) + File.open( filepath ) do |f| + load( f ) + end + end + # # Parse the first document from the current _io_ stream # @@ -150,6 +162,32 @@ module YAML yp = @@parser.new( :Model => :Generic ).load( io ) end + # + # Parse a document from the file located at _filepath_. + # + # YAML.parse_file( 'animals.yaml' ) + # #=> #<YAML::Syck::Node:0x82ccce0 + # @kind=:seq, + # @value= + # [#<YAML::Syck::Node:0x82ccd94 + # @kind=:scalar, + # @type_id="str", + # @value="badger">, + # #<YAML::Syck::Node:0x82ccd58 + # @kind=:scalar, + # @type_id="str", + # @value="elephant">, + # #<YAML::Syck::Node:0x82ccd1c + # @kind=:scalar, + # @type_id="str", + # @value="tiger">]> + # + def YAML.parse_file( filepath ) + File.open( filepath ) do |f| + parse( f ) + end + end + # # Calls _block_ with each consecutive document in the YAML # stream contained in _io_. |