From ed4816b4955059d169facf27e457ecc215943d51 Mon Sep 17 00:00:00 2001 From: why Date: Thu, 15 Jul 2004 05:04:49 +0000 Subject: * lib/yaml.rb (YAML::load_file, YAML::parse_file): added. * ext/syck/token.c: re2c compiled with bit vectors now. * ext/syck/implicit.c: ditto. * ext/syck/bytecode.c: ditto. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@6634 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 023c4ab84..38463404b 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