From a2523332ce58ab4af4f531306ebbdf10bacaa892 Mon Sep 17 00:00:00 2001 From: why Date: Fri, 30 Jul 2004 20:38:41 +0000 Subject: * 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 --- lib/yaml.rb | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'lib/yaml.rb') 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' ) + # #=> #, + # #, + # #]> + # + 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_. -- cgit v1.2.3